Access Violation during MFC execution of CFrameWnd::InitialUpdateFrame

0

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);

winfrm.cpp:

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

afxwin2.inl:

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

wincore.cpp:

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

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

wincore.cpp:

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);
    dc->set_raw_file(raw);

    frame->InitialUpdateFrame(dc, TRUE);
    
    if (app_multiplexed == SINGLE)
        menu.LoadMenu(IDR_REMPLETYPE_SINGLE);
    else
        menu.LoadMenu(IDR_REMPLETYPE);

    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!

c++
mfc
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