我在从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


我不断得到Additional information: Unable to find an entry point named 'SquareRoot' in DLL 'DLL_Test.dll'。当我在dumpbin.exe上运行DLL_Test.dll时,我得到以下信息

File Type: DLL

  Summary

        1000 .data
        1000 .idata
        2000 .rdata
        1000 .reloc
        1000 .rsrc
        4000 .text
       10000 .textbss


我不确定我缺少什么,有什么想法吗?提前致谢。

最佳答案

名字改头换面。 extern "C"不会将其关闭,它只会更改规则。

您也有一个呼叫约定不匹配。

您可以通过C ++函数上的__stdcall关键字一次解决这两个问题。

关于c++ - 为什么会收到“无法在DLL中找到名为'Square Root'的入口点”消息?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32957665/

10-17 02:02