【发布时间】:2011-12-30 14:25:42
【问题描述】:
我使用 GetProcAddress 从 C++ dll 将 GetInstance 函数加载到我的基本代码并获取 一些未解决的外部符号错误:
错误LNK2019:无法解析的外部符号“_declspec(dllimport) 公共:无符号整数 _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))?!
任何想法为什么这不起作用?
提前谢谢你!
问候
【问题讨论】:
-
我们需要
SetUserDescriptor的代码,以及CTestmode_Sle70::SetMSfr的声明和定义,而不是所有发布的代码。
标签: c++ dll calling-convention unresolved-external