2012-07-05 145 views
0

我需要以下功能(從C++ DLL)在C語言++/CLIC++/CLI包裝LNK2028和LNK2019錯誤

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 *)" ([email protected]@[email protected]@@Z) referenced in function "private: __clrcall MKeyManagerInterface::ManagedKeyInterface::~ManagedKeyInterface(void)" ([email protected]@@[email protected]) 
1>MKeyManagerInterface.obj : error LNK2019: unresolved external symbol "extern "C" void __stdcall DestroyInstance(class CKeyManagerServerApp *)" ([email protected]@[email protected]@@Z) referenced in function "private: __clrcall MKeyManagerInterface::ManagedKeyInterface::~ManagedKeyInterface(void)" ([email protected]@@[email protected]) 
1>..\Debug\Bin\KeyManagerInterfaceD.dll : fatal error LNK1120: 2 unresolved externals 

我怎樣才能解決這個鏈接錯誤?

Thx

回答

2

您不應該從C++/CLI中使用P/Invoke。您應該能夠包含聲明導入函數的常用C/C++頭文件。只要確保將C++/CLI程序集與導出相關函數的本機代碼DLL中的導出庫鏈接起來即可。

+0

是的,但如果我想在運行時加載庫鏈接反對庫不適合! – leon22 2012-07-05 11:00:21

+0

@ leon22但是你從來沒有聲明,作爲你的文章中的要求:)你可以像使用非託管Windows C/C++代碼一樣使用'LoadLibrary' +'GetProcAddress'嗎? – reuben 2012-07-05 11:01:41

+0

是的,這是我的第一個主意!但我總是得到奇怪的記憶錯誤!請參閱:http://stackoverflow.com/questions/11306602/heap-error-in-c-sharp – leon22 2012-07-05 11:15:30