2
votes

During the proccess of linking the LNK2001 error happens:

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

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)

1
Since you're using DECLARE_DYNAMIC you need the IMPLEMENT_DYNAMIC. Your question is not about linking. It is about run-time behavior of your program, and you have provided next to no information about that. Fire up your debugger. Find out what's going on.Cheers and hth. - Alf
You are driving from CDialog. But then you switch to CWnd in IMPLEMENT_DYNAMIC and in BEGIN_MESSAGE_MAP. From the look of your declarations I don't know if that's meant to be CDialog or CWnd or CView. For the time being comment out DECLARE_DYNAMIC. Also you should explain roughly what sort of view model you are after (dialog or multi-document view or single-document...)Barmak Shemirani

1 Answers

3
votes

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.