我使用 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) 在函数“int __cdecl SetUserDescriptor(unsigned char,unsigned int,unsigned int ) 中引用)" (?SetUserDescriptor@@YAHEII@Z)
DLL 代码
标题
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;
}
工具代码
typedef CTestmode* (*CTestModeInstance)(void);
CTestmode *pMyTM;
...
HMODULE handleTestmode;
handleTestmode = LoadLibrary("Testmode.dll");
CTestModeInstance cTestModeInstance = (CTestModeInstance)GetProcAddress(handleTestmode, "GetInstance");
pMyTM = (cTestModeInstance)();
我的想法是调用约定有问题(查看错误消息 -> __thiscall 和 __cdecl 提示:两个项目都设置为 __cdecl (/Gd))?!
任何想法为什么这不起作用?
先感谢您!
打招呼