exeとdllの2つのMFCプロジェクトがあります。exeはdllを参照します。exeプロジェクトからいくつかのクラスを抽出してdllを作成しました。これが、私の出発点でした。
dllは正常にビルドされますが、exeはdllのクラスの1つのコンストラクターとリンクできません。クラス全体を__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)" (??0CMessageBoxDialog@@QAE@PAVCWnd@@V?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@1IVCPoint@@I@Z) referenced in function "private: void __thiscall CMsgBoxTestDlg::OnDisplayMessageBox(void)" (?OnDisplayMessageBox@CMsgBoxTestDlg@@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を拡張します