![](/img/trans.png)
[英]"Unable to find an entry point named [function] in dll" (c++ to c# type conversion)
[英]Unable to find Entry Point while using C++ dll in C# application
我编写了一个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问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.