为什么我会收到"Unable to find an entry point named 'SquareRoot' in DLL"消息?

Why am I getting a "Unable to find an entry point named 'SquareRoot' in DLL" message?

本文关键字:named 消息 DLL point SquareRoot in entry Unable an find to      更新时间:2023-10-16

我在VB.net项目中从dll调用c++函数有麻烦。我尝试过下面的简单示例

c++ dll

#include <cmath>
extern "C" __declspec(dllexport) double SquareRoot(double value)
{
    return pow(value, 0.5);
}

我构建dll并将其复制到VB.net文件夹

For VB.net project

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'。当我在DLL_Test.dll上运行dumpbin.exe时,我得到以下

File Type: DLL
  Summary
        1000 .data
        1000 .idata
        2000 .rdata
        1000 .reloc
        1000 .rsrc
        4000 .text
       10000 .textbss

我不知道我错过了什么,任何想法?

Name mangling。extern "C"不会关闭它,它只是改变了规则。

你也有一个调用约定不匹配。

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