Reputation: 5649
I need following function (from C++ dll) available in C++/CLI
extern "C" _declspec(dllexport) void __stdcall DestroyInstance(CKeyManagerServerApp *ptr);
My try:
[DllImport("KeyManagerServer.dll", CallingConvention=CallingConvention::StdCall)]
void DestroyInstance(CKeyManagerServerApp IntPtr);
The C++/CLI wrapper is compiled with /clr and stdcall (C++ dll also with stdcall)!
I got following errors:
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
How can I solve this linker errors?
Thx
Upvotes: 0
Views: 2284
Reputation: 3370
You shouldn't need to use P/Invoke from C++/CLI. You should be able to include the usual C/C++ header files that declare the imported function. Just make sure to link your C++/CLI assembly against the export library from the native-code DLL that exports the function in question.
Upvotes: 2