我需要以下功能(来自C++ dll)在C++/CLI 中可用
extern "C" _declspec(dllexport) void __stdcall DestroyInstance(CKeyManagerServerApp *ptr);
我的尝试:
[DllImport("KeyManagerServer.dll", CallingConvention=CallingConvention::StdCall)]
void DestroyInstance(CKeyManagerServerApp IntPtr);
C++/CLI 包装器是用/clr 和 stdcall 编译的(C++ dll 也用 stdcall 编译)!
我收到以下错误:
MKeyManagerInterface.obj : error LNK2028: unresolved token (0A000585) "extern "C" void __stdcall DestroyInstance(class CKeyManagerServerApp *)" (?DestroyInstance@@$$J14YGXPAVCKeyManagerServerApp@@@Z) referenced in function "private: __clrcall MKeyManagerInterface::ManagedKeyInterface::~ManagedKeyInterface(void)" (??1ManagedKeyInterface@MKeyManagerInterface@@$$FA$AAM@XZ)
1>MKeyManagerInterface.obj : error LNK2019: unresolved external symbol "extern "C" void __stdcall DestroyInstance(class CKeyManagerServerApp *)" (?DestroyInstance@@$$J14YGXPAVCKeyManagerServerApp@@@Z) referenced in function "private: __clrcall MKeyManagerInterface::ManagedKeyInterface::~ManagedKeyInterface(void)" (??1ManagedKeyInterface@MKeyManagerInterface@@$$FA$AAM@XZ)
1>..DebugBinKeyManagerInterfaceD.dll : fatal error LNK1120: 2 unresolved externals
如何解决此链接器错误?
感谢
你不需要从 C++/CLI 使用 P/Invoke。您应该能够包含声明导入函数的常用 C/C++ 头文件。只需确保将 C++/CLI 程序集链接到导出相关函数的本机代码 DLL 中的导出库。