我在C ++中有一个简单的函数(不是类的方法)
__declspec(dllexport) extern "C" void __stdcall TestFunc();
我尝试从C#中调用它:
[DllImport("ImportTest.dll")]
public static extern void TestFunc();
...
TestFunc();
它将引发“找不到入口点”异常。
怎么了?
感谢你们对我的帮助 :)
最佳答案
在C ++函数中,在标头(如果您的函数在标头中声明)处添加
extern "C" _declspec(dllexport) void TestFunc();
在函数定义中使用
_declspec(dllexport) void TestFunc()
{
}
在C#端,您需要声明一个类似
[DllImport(@"ImportTest.dll",
EntryPoint = "TestFunc",
ExactSpelling = false,
CallingConvention = CallingConvention.Cdecl)]
static extern void NewTestFunc()
现在使用NewTestFunc()