Access Violation during MFC execution of CFrameWnd::InitialUpdateFrame


I am in the process of trying to upgrade a VC++ 6.0 project to the latest version and am running into an issue. The program starts up fine but in the process of creating two child windows within the main view it crashes with an access violation. When run in debug mode it cannot find the exact location where the error occurs, displaying "Frame not in module" and "The current stack frame was not found in a loaded module. Source cannot be shown for this location" making it difficult to pinpoint the exact issue.

Going through the program step by step reveals that the error lies in the call of CFrameWnd::InitialUpdateFrame.

From there it goes into the following functions: Main.cpp:

frame->InitialUpdateFrame(dc, TRUE);


SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);


CWnd::SendMessageToDescendants(m_hWnd, message, wParam, lParam, bDeep, bOnlyPerm);


SendMessageToDescendants(hWndChild, message, wParam, lParam, bDeep, bOnlyPerm);

(Recursion to same function, error occurs on second recursion)


AfxCallWndProc(pWnd, pWnd->m_hWnd, message, wParam, lParam);

Error has occurred at 3 of the following locations: wincore.cpp:

_AfxPreInitDialog(pWnd, &rectOld, &dwStyle);

lResult = pWnd->WindowProc(nMsg, wParam, lParam);

_AfxPostInitDialog(pWnd, rectOld, dwStyle);

It is called from this function (simplified):

CDocument* XApp::OpenDocumentFile(LPCTSTR lpszFileName) 

    doc_x_spc *dc = 
            static_cast<doc_x_spc *> ( m_spc_template->CreateNewDocument() );

    CMDIChildWnd *frame = 
        static_cast<CMDIChildWnd *> ( m_spc_template->CreateNewFrame(dc, NULL) );

    if ( !dc->OnOpenDocument(lpszFileName) )
        AfxMessageBox( IDS_SPCOPENERROR, MB_OK, NULL );

        return NULL;

    CString raw(lpszFileName);

    frame->InitialUpdateFrame(dc, TRUE);
    if (app_multiplexed == SINGLE)

    CMainFrame* pMainFrame = (CMainFrame *)m_pMainWnd;

    pMainFrame->MDISetMenu(&menu, NULL);
    return dc;

The access violation produces this exact error: Exception thrown at 0x01144008 in X.exe: 0xC0000005: Access violation executing location 0x01144008.

Would appreciate any help. Thank you!

asked on Stack Overflow Apr 22, 2021 by catokass • edited Apr 22, 2021 by catokass

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0