【问题标题】:Why am I getting a "Unable to find an entry point named 'SquareRoot' in DLL" message?为什么我会收到“无法在 DLL 中找到名为‘SquareRoot’的入口点”消息?
【发布时间】:2016-01-02 15:28:19
【问题描述】:

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

File Type: DLL

  Summary

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

我不确定我错过了什么,有什么想法吗?提前致谢。

【问题讨论】:

  • 你在运行dumpbin时是否使用了/exports
  • 另外,全局pow函数来自&lt;math.h&gt;&lt;cmath&gt; 改为提供 std::pow
  • 听起来您可能会在 C++ 端遇到名称修改问题。您可以使用 Dependency Walker(dependencywalker.com) 查看 C++ 代码正在导出的实际函数名称。另外,这个问题可能会有所帮助:stackoverflow.com/questions/1467144/…

标签: c++ vb.net dll pinvoke unmanaged


【解决方案1】:

名称修改。 extern "C" 并没有关闭它,它只是改变了规则。

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

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

【讨论】:

  • 感谢您的回答,但我已将 extern "C" __declspec(dllexport) double SquareRoot(double value) 更改为 double __stdcall SquareRoot(double value) 但我仍然遇到同样的错误
  • 我的意思是把它和现有的代码结合起来,而不是去掉旧的注释。
  • 我不确定我是否在关注,抱歉这一天很长 :)
  • __stdcall 在 C++ 端仍然会导致一个装饰名称。最简单的就是两边__cdecl,避免装饰。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-05
  • 2017-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-14
  • 1970-01-01
相关资源
最近更新 更多