2011-11-16 31 views
0

我加載從GetProcAddress的一個C++ DLL中的GetInstance功能到我的基本代碼,並得到 一些未解決的外部符號錯誤:解析的外部符號 - LNK2019從C++ DLL

錯誤LNK2019:解析的外部符號「 _ declspec(dllimport的) 市民:無符號整型 _thiscall RegTestAPI :: CTestmode_Sle70 :: SetMSfr(無符號整數,無符號短,焦炭 *)」(_ 小鬼 SetMSfr @ CT? estmode_Sle70 @ @@ RegTestAPI @ QAEIIGPAD Z)在函數引用 「INT __cdecl SetUserDescriptor(無符號 炭,無符號整型,無符號整型)」(?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))?!

任何想法,爲什麼這不起作用?

預先感謝您!

迎接

+0

代替所有發佈的代碼,我們需要'SetUserDescriptor'的代碼,以及'CTestmode_Sle70 :: SetMSfr'的聲明和定義。 – Dialecticus

回答

0

你缺少一個實施SetMSfr(unsigned int,unsigned short,char *);

0

錯誤消息不容易閱讀,但它是不言自明的。函數CTestmode_Sle70::SetMSfr在函數SetUserDescriptor中被引用,但它沒有在任何地方定義。鏈接器無法將呼叫綁定到SetMSfr,因爲該函數不存在。

相關問題