简体   繁体   English

无法解析的外部符号-C ++ DLL中的LNK2019

[英]Unresolved external symbol - LNK2019 from C++ dll

I load a GetInstance function from a C++ dll with GetProcAddress to my base code and get some Unresolved external symbol errors: 我将带有GetProcAddress的C ++ dll中的GetInstance函数加载到我的基本代码中,并得到一些未解决的外部符号错误:

error LNK2019 : unresolved external symbol "_ declspec(dllimport) public: unsigned int 错误LNK2019无法解析的外部符号“ _ 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) _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 code DLL代码

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)) ?! 我的想法是调用约定有问题(请查看错误消息-> __thiscall和__cdecl提示:两个项目都设置为__cdecl(/ Gd))?

Any ideas why this won't work? 任何想法为什么这行不通?

Thank you in advance! 先感谢您!

greets 打招呼

The error message is not easy to read, but it is self-explanatory. 错误消息不容易阅读,但是很容易理解。 Function CTestmode_Sle70::SetMSfr is referenced in function SetUserDescriptor , but it's not defined anywhere. 函数CTestmode_Sle70::SetMSfr在函数SetUserDescriptor引用,但未在任何地方定义。 Linker can't bind a call to SetMSfr because the function does not exist. 链接器无法将调用绑定到SetMSfr因为该函数不存在。

您缺少SetMSfr(unsigned int,unsigned short,char *);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM