0

私は2つのMFCプロジェクト、exeとdllを持っています。 exeはdllを参照します。 exeプロジェクトからいくつかのクラスを抽出してDLLを作成しましたが、それが私の出発点でした。Visual Studio 2005 + MFC:リンカエラー、エクスポートされてもコンストラクタにリンクできません

dllはすぐにビルドできますが、exeはdllのクラスのコンストラクタにリンクできません。私は__declspec(dllexport)をクラス全体で試してみましたが、警告が多すぎるので、__declspec(dllexport)はすべてのパブリックメンバーを代わりにしました。これはコンストラクタを除いてリンクエラーの大部分を解決しました。

エラー(MsgBoxTestはexeファイルで、CustomMessageBoxDlgはDLLです):

MsgBoxTestDlg.obj : error LNK2019: unresolved external symbol "public: __thiscall CMessageBoxDialog::CMessageBoxDialog(class CWnd *,class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >,class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >,unsigned int,class CPoint,unsigned int)" ([email protected]@[email protected]@@[email protected][email protected][email protected]@[email protected]@@@@[email protected]@[email protected]@[email protected]) referenced in function "private: void __thiscall CMsgBoxTestDlg::OnDisplayMessageBox(void)" ([email protected]@@AAEXXZ) 
1>Debug\MsgBoxTest.exe : fatal error LNK1120: 1 unresolved externals 

コンストラクタの宣言(それはオーバーロードされます):エラーによって参照

// Constructor of the class for direct providing of the message strings. 
    __declspec(dllexport) CMessageBoxDialog (CWnd* pParent, CString strMessage, 
     CString strTitle = _T(""), UINT nStyle = MB_OK, CPoint initialPosition = CPoint(0,0), UINT nHelp = 0); 

    // Constructor of the class for loading the strings from the resources. 
    __declspec(dllexport) CMessageBoxDialog (CWnd* pParent, UINT nMessageID, UINT nTitleID = 0, 
     UINT nStyle = MB_OK, CPoint initialPosition = CPoint(0,0), UINT nHelp = 0); 

コンストラクタの使用状況:

//this is a CMsgBoxTestDlg, m_strMessage and m_strTitle are CStrings, nStyle is an UINT, initialPosition is a CPoint 
CMessageBoxDialog dlgMessageBox(this, m_strMessage, m_strTitle, nStyle, initialPosition); 

私はClean + Buildを試しましたが、シガーはありません

編集は:クラスはDECLARE_DYNAMICとIMPLEMENT_DYNAMICマクロを使用し、CDialogの

答えて

0

拡張し、それを解決! CStringは、あなたがプロジェクトオプション(一般 - >文字セット)でUnicodeかMulti-Byteのどちらの文字を使用しているかによって、異なるタイプに解決されるようです。私のDLLはUnicodeを使っていて、私のexeはマルチバイトを使っていました。 MBを使用するようにDLLを変更し、うまく構築しました。

関連する問題