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は function で参照されていますSetUserDescriptorが、どこにも定義されていません。関数が存在しないため、リンカーは呼び出しをバインドできませSetMSfrん。

于 2011-11-16T16:53:28.910 に答える
0

の実装がありませんSetMSfr(unsigned int,unsigned short,char *);

于 2011-11-16T16:37:37.670 に答える