无法解析的外部符号 - 来自 C++ 的 LNK2019动态链接库
我使用 GetProcAddress 从 C++ dll 加载 GetInstance 函数到我的基本代码并得到 一些未解决的外部符号错误:
错误LNK2019:无法解析的外部符号“_declspec(dllimport) 公共:无符号整数_thiscall RegTestAPI::CTestmode_Sle70::SetMSfr(无符号整型、无符号短整型、字符 *)" (_imp?SetMSfr@CTestmode_Sle70@RegTestAPI@@QAEIIGPAD@Z) 在函数“int __cdecl SetUserDescriptor(unsigned) 中引用 字符,无符号整数,无符号整数)”(?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))?!
什么想法为什么这不起作用吗?
有
问候
I load a GetInstance function from a C++ dll with GetProcAddress to my base code and get
some Unresolved external symbol errors:
error LNK2019: unresolved external symbol "_declspec(dllimport)
public: unsigned int _thiscall
RegTestAPI::CTestmode_Sle70::SetMSfr(unsigned int,unsigned short,char
*)" (_imp?SetMSfr@CTestmode_Sle70@RegTestAPI@@QAEIIGPAD@Z) referenced in function "int __cdecl SetUserDescriptor(unsigned
char,unsigned int,unsigned int)" (?SetUserDescriptor@@YAHEII@Z)
DLL code
header
extern "C" _declspec(dllexport) CTestmode* GetInstance();
source
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)();
My idea is that something with the calling conventions are wrong (look at the error message -> __thiscall and __cdecl Hint: both projects are set to __cdecl (/Gd)) ?!
Any ideas why this won't work?
Thank you in advance!
greets
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该错误消息不太容易阅读,但它是不言自明的。函数
CTestmode_Sle70::SetMSfr
在函数SetUserDescriptor
中被引用,但它没有在任何地方定义。链接器无法绑定对SetMSfr
的调用,因为该函数不存在。The error message is not easy to read, but it is self-explanatory. Function
CTestmode_Sle70::SetMSfr
is referenced in functionSetUserDescriptor
, but it's not defined anywhere. Linker can't bind a call toSetMSfr
because the function does not exist.您缺少
SetMSfr(unsigned int,unsigned Short,char *); 的实现;
You're missing an implementation for
SetMSfr(unsigned int,unsigned short,char *);