我复制了一个 dlg 框类的现有 header (使用 dlg 类向导/mfc 向导创建)。在我将 cpp 文件添加到项目之前,一切似乎都很顺利。现在我得到一些 mfc 魔术方法的奇怪链接错误:
error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall DlgGapWindow::GetRuntimeClass(void)const " (?GetRuntimeClass@DlgGapWindow@@UBEPAUCRuntimeClass@@XZ)
error LNK2001: unresolved external symbol "protected: virtual struct AFX_MSGMAP const * __thiscall DlgGapWindow::GetMessageMap(void)const " (?GetMessageMap@DlgGapWindow@@MBEPBUAFX_MSGMAP@@XZ)
为什么会这样?
这里是header中的相关代码
class DlgGapWindow : public CDialog
{
DECLARE_DYNAMIC(DlgGapWindow)
public:
DlgGapWindow(CWnd* pParent = NULL);
virtual ~DlgGapWindow();
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual BOOL OnInitDialog();
enum { IDD = IDD_DIALOG_GAP_VIEW };// Dialog Data
GapViewer m_chart;
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnSizing(UINT fwSide, LPRECT pRect) ;
afx_msg void OnTimer(ONTIMER_TYPE nIDEvent);
afx_msg void OnDestroy();
afx_msg void OnClose();
afx_msg void OnActivate(UINT,CWnd *,BOOL);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
DECLARE_MESSAGE_MAP()
};
我没有看到我建模的类中的任何内容似乎都丢失了。我没有发现任何有用的谷歌或其他搜索来说明为什么缺少这些神奇的 mfc 东西。我的其他类没有明确定义它们,它们也没有错误。
RC文件确实有相应的dlg定义。
编辑:
感谢 DECLARE_DYNAMIC 的帮助 - 现在我没有 GetRuntimClass() 错误 - 只有 GetMessagemap() 错误。
最佳答案
您使用了 DECLARE_DYNAMIC 但忘记了 IMPLEMENT_DYNAMIC .
关于c++ - MyClass::GetMessageMap() 和 MyClass::GetRuntimeClass (MSVC 2008) 的 MFC dlg 类链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5150056/