在c#应用程序中使用c++ dll时无法找到入口点
本文关键字:入口 dll 应用程序 c++ | 更新日期: 2023-09-27 17:49:01
我写了一个c#应用程序,需要在一个按钮点击上调用c++ dll中的函数。但在点击按钮时,它抛出'EntryPointNotFound'异常。
Below is the code snippet of C#
public class Test
{
[DllImport("Demo.dll", EntryPoint = "OpenFile"]
public static extern bool OpenFile(string fileName);
}
private void button1_Click_1(object sender, EventArgs e)
{
bool check = Test.OpenFile("test.txt"); // exception thrown at this point
if (check)
{
// Not entering this area..
}
}
C++ Header (.h file)
__declspec(dllexport) bool OpenFile(CString fileName);
Cpp class (.cpp )
__declspec(dllexport) bool Demo::OpenFile(CString fileName)
{
return true;
}
请帮。
基本上你需要在dll代码中添加extern "C":
extern "C" __declspec(dllexport) bool OpenFile(CString fileName);
也看到stackoverflow问题