c#
[DllImport(".dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr DllCreateObject();
//两数相加
[DllImport(".dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int DllAdd(IntPtr dllObject, int a, int b);
[DllImport(".dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void destoryStreamE(IntPtr dllObject);
IntPtr dllObject = DllCreateObject();
int c = DllAdd(dllObject, 1, 2);
destoryStreamE(dllObject);
c++
.h文件
#define DLL_API extern "C" _declspec(dllexport)
class model
{
public:
int i;
model() {}
~model() {}
int Add(const int a, const int b)
{
return a + b;
}
};
.cpp
DLL_API void* DllCreateObjectE()
{
model* p = new model();
return p;
}
DLL_API void destory(void* pCAdd) {
model* p = (model*)pCAdd;
return p-> ~model();
};
DLL_API int DllAdd(void* pCAdd, int a, int b)
{
model* p = (model*)pCAdd;
return p->Add(a, b);
}



