我将带有GetProcAddress的C dll中的GetInstance函数加载到我的基本代码中,并得到一些未解决的外部符号错误:
错误LNK2019:未解析的外部符号“_declspec(dllimport)public:unsigned int thiscall RegTestAPI :: CTestmode_Sle70 :: SetMSfr(unsigned int,unsigned short,char *)”( imp?SetMSfr @ CTestmode_Sle70 @RegTestAPI @@ QAEIIGPAD @ Z)引用in function“int __cdecl SetUserDescriptor(unsigned char,unsigned int,unsigned int)”(?SetUserDescriptor @@ YAHEII @ Z)
DLL code
头
extern "C" _declspec(dllexport) CTestmode* GetInstance();
资源
CTestmode *cTestmode;
extern "C" _declspec(dllexport) CTestmode* GetInstance()
{
cTestmode = CTestmode::Instance();
return cTestmode;
}
...
// in header
static CTestmode* Instance();
...
static CTestmode* m_pInstance;
// in source
CTestmode* CTestmode::Instance()
{
if(m_pInstance == NULL)
{
m_pInstance = new CTestmode();
}
return m_pInstance;
}
Tool code
typedef CTestmode* (*CTestModeInstance)(void);
CTestmode *pMyTM;
...
HMODULE handleTestmode;
handleTestmode = LoadLibrary("Testmode.dll");
CTestModeInstance cTestModeInstance = (CTestModeInstance)GetProcAddress(handleTestmode, "GetInstance");
pMyTM = (cTestModeInstance)();
我的想法是调用约定的东西是错误的(查看错误消息 - > __thiscall和__cdecl提示:两个项目都设置为__cdecl(/ Gd))?
任何想法为什么这不起作用?
先感谢您!
招呼
2 回答
您错过了
SetMSfr(unsigned int,unsigned short,char *);
的实施错误消息不容易阅读,但它是不言自明的 . 函数
SetUserDescriptor
在函数SetUserDescriptor
中引用,但它's not defined anywhere. Linker can' t绑定对SetMSfr
的调用,因为该函数不存在 .