Reputation: 5639
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
Upvotes: 1
Views: 2294
Reputation: 16761
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. Linker can't bind a call to SetMSfr
because the function does not exist.
Upvotes: 1
Reputation: 8815
You're missing an implementation for SetMSfr(unsigned int,unsigned short,char *);
Upvotes: 0