1
votes

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

2
Instead of all the posted code we need the code of SetUserDescriptor, and declaration and definition of CTestmode_Sle70::SetMSfr.Dialecticus

2 Answers

1
votes

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.

0
votes

You're missing an implementation for SetMSfr(unsigned int,unsigned short,char *);