Henry1996
Henry1996

Reputation: 25

How to get rid of linking error in mfc?

During the proccess of linking the LNK2001 error happens:

Why would this be?

Here is the relevant code in the header:

class CChildView :public CDialog
{

    DECLARE_DYNAMIC(CChildView)

public:

    CChildView();
    ~CChildView();
    afx_msg void OnPaint();
    afx_msg void OnLevelProf();
    afx_msg void OnLevelAmat();
    afx_msg void OnLevelBeg();
    afx_msg void OnStepC();
    void new_game();
    //void CloseWindow();
    BOOL PreCreateWindow(CREATESTRUCT& cs);
    int end_analyze();
    void ii();
    unsigned long calculate(int id, int x, int y);
    afx_msg void OnNewGame();
    //void Invalidate();
    afx_msg void OnX1010();
    afx_msg void OnX1919();
    afx_msg void OnX3030();
    afx_msg void OnX5050();
    afx_msg void OnX100100();
    //MessageBoxW();
    void resize_window();
    afx_msg void OnLButtonDown(UINT, CPoint xy);
    //void GetWindowRect(RECT);
    //int MessageBoxW();
     void OnStepH();
    void set_chеcked_menu(unsigned int old_id, unsigned int new_id);
    DECLARE_MESSAGE_MAP()
};

And the part of .cpp file:

//IMPLEMENT_DYNAMIC(CChildView, CWnd)//!without this - doesn`t compiles. With - //runtime failure
BEGIN_MESSAGE_MAP(CChildView, CWnd)
    ON_WM_PAINT()
    ON_WM_LBUTTONDOWN()
    .....
    END_MESSAGE_MAP()

But during the execution of my programm (if implement_dynamicaly is uncommented) it fails in AfxWinMain function on the line:

if (!pThread->InitInstance())

My other classes don't explicitly define them and they don't have errors. Here is somethink like this, but it didn`t help me. MFC dlg class link errors for MyClass::GetMessageMap() and MyClass::GetRuntimeClass (MSVC 2008)

Upvotes: 2

Views: 978

Answers (1)

Joseph Willcoxson
Joseph Willcoxson

Reputation: 6050

You commented out the line IMPLEMENT_DYNAMIC(CChildView, CWnd).

You need to either comment out the DECLARE_DYNAMIC() macro in your CChildView class, or uncomment out the IMPLEMENT_DYNAMIC--they have to do with the CRuntimeClass for your class. Also, if you uncomment out the IMPLEMENT_DYNAMIC, you should make sure the baseclass in the macro matches the class you are deriving from. IOW, it should say CDialog and not CWnd. Also, your BEGIN_MESSAGE_MAP() suffers from the same problem.

Upvotes: 4

Related Questions