Entry Point Not Found Exception

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.

14
задан JaredPar 18 August 2010 в 18:24
поделиться

2 ответа

Используя утилиту 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);
16
ответ дан 1 December 2019 в 10:32
поделиться

Похоже, что функция, которую вы пытаетесь вызвать, скомпилирована как функция C++ и поэтому ее имя искажено. PInvoke не поддерживает искаженные имена. Вам нужно добавить блок extern "C" вокруг определения функции, чтобы предотвратить искажение имени

extern "C" {
  void* aaeonAPIOpen(uint reserved);
}
9
ответ дан 1 December 2019 в 10:32
поделиться
Другие вопросы по тегам:

Похожие вопросы: