C ++ / CLI包装器LNK2028和LNK2019错误

时间:2012-07-05 09:44:09

标签: c++ dll c++-cli dllimport lnk

我需要以下C ++ / CLI中提供的函数(来自C ++ dll)

extern "C" _declspec(dllexport) void __stdcall DestroyInstance(CKeyManagerServerApp *ptr);

我的尝试:

[DllImport("KeyManagerServer.dll", CallingConvention=CallingConvention::StdCall)]
void DestroyInstance(CKeyManagerServerApp IntPtr);

使用/ clr和stdcall编译C ++ / CLI包装器(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>..\Debug\Bin\KeyManagerInterfaceD.dll : fatal error LNK1120: 2 unresolved externals

如何解决此链接器错误?

THX

1 个答案:

答案 0 :(得分:2)

您不需要在C ++ / CLI中使用P / Invoke。您应该能够包含声明导入函数的常用C / C ++头文件。只需确保将C ++ / CLI程序集与导出相关函数的本机代码DLL中的导出库相链接。