未找到入口点异常

发布于 2024-09-15 11:20:25 字数 613 浏览 8 评论 0原文

我尝试在 C# 项目中使用 C++ 非托管 dll,但在尝试调用函数时遇到错误,提示无法找到入口点。

public class Program
{

    static void Main(string[] args)
    {
        IntPtr testIntPtr = aaeonAPIOpen(0);            
        Console.WriteLine(testIntPtr.ToString());
    }

    [DllImport("aonAPI.dll")]
    public static extern unsafe IntPtr aaeonAPIOpen(uint reserved);
}

这是该函数的转储箱:

5    4 00001020 ?aaeonAPIOpen@@YAPAXK@Z

我将 dll 导入更改为 [DllImport("aonAPI.dll", EntryPoint="?aaeonAPIOpen")][DllImport("aonAPI.dll" , EntryPoint="_aaeonAPIOpen")] 但没有运气。

I'm trying to use a C++ unmanaged dll in a C# project and I'm getting an error when trying to call a function that says that entry point cannot be found.

public class Program
{

    static void Main(string[] args)
    {
        IntPtr testIntPtr = aaeonAPIOpen(0);            
        Console.WriteLine(testIntPtr.ToString());
    }

    [DllImport("aonAPI.dll")]
    public static extern unsafe IntPtr aaeonAPIOpen(uint reserved);
}

Here is the dumpbin for the function:

5    4 00001020 ?aaeonAPIOpen@@YAPAXK@Z

I changed the dll import to [DllImport("aonAPI.dll", EntryPoint="?aaeonAPIOpen")] and [DllImport("aonAPI.dll", EntryPoint="_aaeonAPIOpen")] and no luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痕至 2024-09-22 11:20:25

使用 undname.exe 实用程序,该符号可以分解为

 void * __cdecl aaeonAPIOpen(unsigned long)

Which 做出正确的声明:

    [DllImport("aonAPI.dll", EntryPoint="?aaeonAPIOpen@@YAPAXK@Z", 
        ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
    public static extern IntPtr aaeonAPIOpen(uint reserved);

Using the undname.exe utility, that symbol demangles to

 void * __cdecl aaeonAPIOpen(unsigned long)

Which makes the proper declaration:

    [DllImport("aonAPI.dll", EntryPoint="?aaeonAPIOpen@@YAPAXK@Z", 
        ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
    public static extern IntPtr aaeonAPIOpen(uint reserved);
高跟鞋的旋律 2024-09-22 11:20:25

看起来您尝试调用的函数被编译为 C++ 函数,因此其名称已被破坏。 PInvoke 不支持损坏的名称。您需要在函数定义周围添加外部“C”块以防止名称修改

extern "C" {
  void* aaeonAPIOpen(uint reserved);
}

It looks like the function you're trying to call is compiled as a C++ function and hence has it's name mangled. PInvoke does not support mangled name. You need to add an extern "C" block around the function definition to prevent name mangling

extern "C" {
  void* aaeonAPIOpen(uint reserved);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文