0
**unmanaged class**
這是不受控類聲明使用託管C++ DLL在c#
#ifdef EXPORT_CLASS
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
public class DLL_EXPORT cppclass
{
private:
string x;
public:
cppclass();
~cppclass();
string native();
};
**UNMANAGED CLASS DEFINITION**
這是不受控類定義
cppclass::cppclass()
{
x="hello";
};
cppclass::~cppclass()
{
};
string cppclass::native()
{
return x;
};
**MANAGED CLASS**
這是被管理的類聲明
public __gc class Mclass
{
//private:
public:
cppclass * obj;
public:
Mclass();
~Mclass();
string native();
};
**MANAGED CLASS DEFINITION**
//這是管理類定義
#include"managed.h"
Mclass::Mclass()
{
obj=new cppclass();
};
Mclass::~Mclass()
{
delete obj;
};
string Mclass::native()
{
return obj->native();
};
Now all this is made into a dll and imported in a c# project
using managed;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
managed.Mclass first = new Mclass();
String x=first.nativ();
Console.Out.WriteLine(x);
}
}
}
錯誤出現的是Managed.Mclass.nativ()不是由語言
:謝謝你的工作.... – 2012-02-10 08:11:02