没有找到入口点的例外
我正在尝试在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); }
这是函数的dumpbin:
5 4 00001020 ?aaeonAPIOpen@@YAPAXK@Z
我将dll导入更改为[DllImport("aonAPI.dll", EntryPoint="?aaeonAPIOpen")]
和[DllImport("aonAPI.dll", EntryPoint="_aaeonAPIOpen")]
并且没有运气。
使用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);
看起来你试图调用的函数被编译为C ++函数,因此它的名字被破坏了。 PInvoke不支持受损名称。 您需要在函数定义周围添加一个extern“C”块以防止名称损坏
extern "C" { void* aaeonAPIOpen(uint reserved); }