Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get the message "Unhandled exception thrown: read access violation. this was nullptr " in function GetDlgItem in source file “winocc.cpp” from MFC library

CWnd* CWnd::GetDlgItem(int nID) const
{
	ASSERT(::IsWindow(m_hWnd));

	if (m_pCtrlCont == NULL)
		return CWnd::FromHandle(::GetDlgItem(m_hWnd, nID));
	else
		return m_pCtrlCont->GetDlgItem(nID);
}



This function is called from :
_AfxActivationWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
	WNDPROC oldWndProc = (WNDPROC)::GetProp(hWnd, _afxOldWndProc);
	ASSERT(oldWndProc != NULL);	

	LRESULT lResult = 0;
	TRY
	{
		BOOL bCallDefault = TRUE;
		switch (nMsg)
		{
		case WM_INITDIALOG:
			{
				DWORD dwStyle;
				CRect rectOld;
				CWnd* pWnd = CWnd::FromHandle(hWnd);
				_AfxPreInitDialog(pWnd, &rectOld, &dwStyle);
				bCallDefault = FALSE;
				lResult = CallWindowProc(oldWndProc, hWnd, nMsg, wParam, lParam);
				_AfxPostInitDialog(pWnd, rectOld, dwStyle);
			}
			break;


What I have tried:

I cant watch the value of m_pCtrlCont and the value of "this" is NULL
Posted
Updated 9-Mar-17 23:59pm
Comments
Richard MacCutchan 5-Mar-17 9:25am    
Something has not been initialised correctly; you will need to use your debugger to find out where and how.
Richard MacCutchan 10-Mar-17 6:08am    
My previous comment still applies. The bug is in your code, it is caught in the library functions. The only way to find out what is happening is to use your debugger and trace your code.

1 solution

If the value of this is NULL happens, when you had done something very wrong.

The m_pCtrlCont is used for some advanced use of the CFileDialog to enhance the dialog with a addtional windows.

I guess that you havent instanciated the CFileDialog object, but used pointer which is NULL. Start debugging where you create the dialog.

Take a look at the Microsoft documentation with an example.
 
Share this answer
 
Comments
GKSHR 6-Mar-17 2:52am    
First thanks for your reply, I don't think that the pointer is really NULL because when I use a different function for the same instance (DWORD CWnd::GetStyle() function) I see that the pointer is initialised.
This code is converted from Visual C++ 6.0 to Visual Studio 2015, do you know about difference in class CFileDialog ?

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