R
Rich
Yes, I'm a noob with .NET looking for help.
My goal is to eventually write a managed DLL in C++ that is a wrapper
for an unmanaged C DLL, then use the managed DLL in C#, VB, etc.
Initially, I am just trying to write a very simple managed DLL in C++
and use it from C#. In my C++ DLL I define a namespace containing one
public class, this class contains a couple public functions. In C# I
reference the DLL and I can see the namespace and class, but I cannot
see any members of the class. What am I doing wrong?
Here are the details . . .
My C++ DLL project contains one source file that looks like this:
#define DLLEXPORT __declspec( dllexport )
namespace test_ns {
public class DLLEXPORT testclass {
public:
int x, y;
int add_function(int a, int b)
{
return(a + b);
}
int sub_function(int a, int b)
{
return(a - b);
}
};
}
On the C# side this is what I have:
using System;
using System.Collections.Generic;
using System.Text;
using test_ns;
using anothername;
namespace anothername
{
public class anotherclass
{
public int x, y;
public int addstuff(int a, int b)
{
return (a + b);
}
}
}
namespace MyFirstApplication
{
class Program
{
static void Main(string[] args)
{
int i;
testclass tc = new testclass();
anotherclass ac = new anotherclass();
/*
* At this point, I can see testclass but
* I cannot access any members (variables
* or functions) - ???
*/
// The compiler chokes on this with the error
// 'test_ns.testclass' does not contain a definition for
'add_function'
i = tc.add_function(5, 6);
// This works fine (class defined in C#)
i = ac.addstuff(12, 13);
Console.WriteLine("i = " + i);
}
}
}
I'm sure there is something simple I am missing. Can anybody enlighten
me on this issue?
My goal is to eventually write a managed DLL in C++ that is a wrapper
for an unmanaged C DLL, then use the managed DLL in C#, VB, etc.
Initially, I am just trying to write a very simple managed DLL in C++
and use it from C#. In my C++ DLL I define a namespace containing one
public class, this class contains a couple public functions. In C# I
reference the DLL and I can see the namespace and class, but I cannot
see any members of the class. What am I doing wrong?
Here are the details . . .
My C++ DLL project contains one source file that looks like this:
#define DLLEXPORT __declspec( dllexport )
namespace test_ns {
public class DLLEXPORT testclass {
public:
int x, y;
int add_function(int a, int b)
{
return(a + b);
}
int sub_function(int a, int b)
{
return(a - b);
}
};
}
On the C# side this is what I have:
using System;
using System.Collections.Generic;
using System.Text;
using test_ns;
using anothername;
namespace anothername
{
public class anotherclass
{
public int x, y;
public int addstuff(int a, int b)
{
return (a + b);
}
}
}
namespace MyFirstApplication
{
class Program
{
static void Main(string[] args)
{
int i;
testclass tc = new testclass();
anotherclass ac = new anotherclass();
/*
* At this point, I can see testclass but
* I cannot access any members (variables
* or functions) - ???
*/
// The compiler chokes on this with the error
// 'test_ns.testclass' does not contain a definition for
'add_function'
i = tc.add_function(5, 6);
// This works fine (class defined in C#)
i = ac.addstuff(12, 13);
Console.WriteLine("i = " + i);
}
}
}
I'm sure there is something simple I am missing. Can anybody enlighten
me on this issue?