Cannot call DLL import entry, C# -> C++, EntryPointNotFoundException

后端 未结 2 669
清歌不尽
清歌不尽 2021-01-29 05:30

I\'m trying to call from C# a function in a custom DLL written in C++. However I\'m getting the warning during code analysis and the error at runtime:

War

相关标签:
2条回答
  • 2021-01-29 05:48

    Well, you know the entry point name, use the EntryPoint = "?SetHook@@YA_NXZ" property in the [DllImport] attribute. Or put extern "C" before the declaration in your C++ code so the name doesn't get mangled.

    [DllImport("wi.dll", EntryPoint = "?SetHook@@YA_NXZ", CallingConvention = CallingConvention.Cdecl)]
    [return: MarshalAsAttribute(UnmanagedType.I1)]
    internal static extern bool SetHook();
    
    0 讨论(0)
  • 2021-01-29 05:49

    CallingConvention.Cdecl means C not C++, so when you have a function with a C++ decorated name, you need to use the decorated name as your EntryPoint or use Extern "C" in The C++ code declaration to turn off C++ name decoration.

    0 讨论(0)
提交回复
热议问题