我编写了一个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;
}
请帮忙。
答案 0 :(得分:0)
基本上你需要添加extern" C"到DLL代码:
extern "C" __declspec(dllexport) bool OpenFile(CString fileName);