1

我使用 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))?!

任何想法为什么这不起作用?

先感谢您!

打招呼

4

2 回答 2

1

错误消息不易阅读,但不言自明。函数CTestmode_Sle70::SetMSfr在函数中被引用SetUserDescriptor,但它没有在任何地方定义。链接器无法绑定调用,SetMSfr因为该函数不存在。

于 2011-11-16T16:53:28.910 回答
0

你错过了一个实现SetMSfr(unsigned int,unsigned short,char *);

于 2011-11-16T16:37:37.670 回答