Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
frame->InitialUpdateFrame(dc, TRUE);


winfrm.cpp:
C++
SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);

afxwin2.inl:
C++
CWnd::SendMessageToDescendants(m_hWnd, message, wParam, lParam, bDeep, bOnlyPerm);

wincore.cpp:
C++
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):
C++
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!

What I have tried:

So far I have gone through the relevant part of the program step by step using the debugger, trying to find any variables that were NULL at any point, but there are no obvious clues. My suspicion is that MFC has changed quite a bit and the code no-longer correctly implements it.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900