1

I want to create a MFC Single Document Application with Visual Studio 2017.

I had made the following Configuration when I create the new Project:

Configuration MFC SD

Configuration MFC SD

Configuration MFC SD

Configuration MFC SD

If i now Build and Run the newly created Project without any changes on the code it immediately crashes with an Debug Assertion Error. This is the Message i got:

enter image description here

It seems the Problem is inside the OnCreate Method of the MainFrame.cpp. The Function gives the pContext Variable with NULL to the m_wndSplitter.Create Function.

This is the OnCreate and OnCreateClient Function of the MainFrame Class:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
        return -1;

    BOOL bNameValid;

    // create a view to occupy the client area of the frame
    if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
    {
        TRACE0("Failed to create view window\n");
        return -1;
    }

    m_wndRibbonBar.Create(this);
    m_wndRibbonBar.LoadFromResource(IDR_RIBBON);

    if (!m_wndStatusBar.Create(this))
    {
        TRACE0("Failed to create status bar\n");
        return -1;      // fail to create
    }

    CString strTitlePane1;
    CString strTitlePane2;
    bNameValid = strTitlePane1.LoadString(IDS_STATUS_PANE1);
    ASSERT(bNameValid);
    bNameValid = strTitlePane2.LoadString(IDS_STATUS_PANE2);
    ASSERT(bNameValid);
    m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE1, strTitlePane1, TRUE), strTitlePane1);
    m_wndStatusBar.AddExtendedElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE2, strTitlePane2, TRUE), strTitlePane2);

    // enable Visual Studio 2005 style docking window behavior
    CDockingManager::SetDockingMode(DT_SMART);
    // enable Visual Studio 2005 style docking window auto-hide behavior
    EnableAutoHidePanes(CBRS_ALIGN_ANY);

    return 0;
}


BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
    CCreateContext* pContext)
{
    return m_wndSplitter.Create(this,
        2, 2,               // TODO: adjust the number of rows, columns
        CSize(10, 10),      // TODO: adjust the minimum pane size
        pContext);
}
Kevin
  • 785
  • 2
  • 10
  • 32
  • 1
    *"Press Retry to debug the application"* - Why didn't you? That takes you straight to the failed debug assertion, giving you valuable context to analyze the issue you have run into. You also need to drop the common misconception: A failed debug assertion dialog is not the same as an application crash. – IInspectable Mar 06 '18 at 07:18
  • That, and also have a look at the call stack that gives you even more context information. Especially if the assertion happens deep in MFC code, you will be able to see where the call originates from your application code. – zett42 Mar 06 '18 at 07:59
  • It originates from the `if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)` i set a breakpoint to that function call but if i want to try to debug into it it directly throws the Debug Assertion. I also pressed retry and this brings me into the `CSplitterWnd::Create(...)` Method where the Assertion is false. The calling function passes null to this function for the `pContext` but i could not find where the `pContext` gets null because of the first mentioned problem with the the `OnCreate` Function. – Kevin Mar 06 '18 at 08:19

1 Answers1

0

I solved the Problem. The Assertion happens because the Document/View Architecture is needed. If i added the Document/View Architecture the Program runs without any problem

Kevin
  • 785
  • 2
  • 10
  • 32