MyClass::GetMessageMap() 和 MyClass::GetRuntimeClass (MSVC 2008) 的 MFC dlg 类链接错误

2022-01-12 00:00:00 visual-studio-2008 linker c++ mfc

我复制了 dlg 框类的现有标题(使用 dlg 类向导/mfc 向导创建).在我将 cpp 文件添加到项目之前,一切似乎都很好.现在我得到一些 mfc 魔术方法的奇怪链接错误:

I copied an existing header for a dlg box class (created with the dlg class wizard/mfc wizard). All seemed to go fine until I added the cpp file to the project. Now i get odd link errors for some mfc magic methods:

错误 LNK2001:未解决的外部符号公共:虚拟结构CRuntimeClass * __thiscallDlgGapWindow::GetRuntimeClass(void)const"(?GetRuntimeClass@DlgGapWindow@@UBEPAUCRuntimeClass@@XZ)

error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall DlgGapWindow::GetRuntimeClass(void)const " (?GetRuntimeClass@DlgGapWindow@@UBEPAUCRuntimeClass@@XZ)

错误 LNK2001:未解决的外部符号受保护:虚拟结构AFX_MSGMAP 常量 * __thiscallDlgGapWindow::GetMessageMap(void)const"(?GetMessageMap@DlgGapWindow@@MBEPBUAFX_MSGMAP@@XZ)

error LNK2001: unresolved external symbol "protected: virtual struct AFX_MSGMAP const * __thiscall DlgGapWindow::GetMessageMap(void)const " (?GetMessageMap@DlgGapWindow@@MBEPBUAFX_MSGMAP@@XZ)

为什么会这样?

这是标题中的相关代码

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 东西丢失了.我的其他类没有明确定义它们,它们也没有错误.

I don't see anything from the class I modeled it after that seems to be missing. I have not found anything useful with google or other searches to indicate why these magic mfc things are missing. My other classes don't explicitly define them and they don't have errors.

RC 文件确实有对应的 dlg 定义.

The RC file does have a corresponding dlg definition.

感谢 DECLARE_DYNAMIC 的帮助 - 现在我没有 GetRuntimClass() 错误 - 只有 GetMessagemap() 错误.

Thanks for the DECLARE_DYNAMIC help - now I do not have the GetRuntimClass() error - just the GetMessagemap() error.

推荐答案

你使用了 DECLARE_DYNAMIC 但忘记了 IMPLEMENT_DYNAMIC.

You used DECLARE_DYNAMIC but forgot IMPLEMENT_DYNAMIC.

相关文章