我无法从 VB.net 项目中的 dll 调用 C++ 函数。我尝试了下面显示的简单示例
对于 C++ dll
#include <cmath>
extern "C" __declspec(dllexport) double SquareRoot(double value)
{
return pow(value, 0.5);
}
我构建 dll 并将其复制到 VB.net 文件夹
对于 VB.net 项目
Module Module1
<Runtime.InteropServices.DllImport("DLL_Test.dll")> _
Private Function SquareRoot(ByVal value As Double) As Double
End Function
Sub Main()
MsgBox(SquareRoot(2))
End Sub
End Module
我不断收到 其他信息:无法在 DLL“DLL_Test.dll”中找到名为“SquareRoot”的入口点
。当我在 DLL_Test.dll
上运行 dumpbin.exe
时,我得到以下信息
File Type: DLL
Summary
1000 .data
1000 .idata
2000 .rdata
1000 .reloc
1000 .rsrc
4000 .text
10000 .textbss
我不确定我错过了什么,有什么想法吗?提前致谢。
最佳答案
名称修改。 extern "C"
不会关闭它,它只是改变了规则。
您还存在调用约定不匹配的问题。
您可以通过 C++ 函数上的 __stdcall
关键字同时解决这两个问题。
关于c++ - 为什么我在 DLL 中收到 "Unable to find an entry point named ' SquareRoot' 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32957665/