【问题标题】:Entry Point Not Found Exception未找到入口点异常
【发布时间】:2010-08-18 18:16:44
【问题描述】:

我正在尝试在 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")],但没有运气。

【问题讨论】:

    标签: c# interop pinvoke


    【解决方案1】:

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

     void * __cdecl aaeonAPIOpen(unsigned long)
    

    正确的声明:

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

    【讨论】:

    • +1,没想到你能做到。这种方法有多安全?错位的名称是否因构建而异,还是在相同代码的构建之间保持一致?
    • @Jared:修改完全基于 C++ 函数的声明。这就是为什么 undname.exe 可以工作的原因。只要声明不改变,它就是稳定的。这使得它比外部“C”声明更安全
    【解决方案2】:

    看起来您尝试调用的函数被编译为 C++ 函数,因此它的名称被破坏了。 PInvoke 不支持错位名称。您需要在函数定义周围添加一个 extern "C" 块以防止名称混淆

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-07
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2015-03-10
      • 2012-09-15
      • 1970-01-01
      相关资源
      最近更新 更多