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) に設定されています) ?!
これがうまくいかない理由はありますか?
前もって感謝します!
挨拶する