Unhandled Exception (MFC42D.DLL): OxC0000005: Access Violation

When I compile a program in Debug mode, I get an error "unhandled exception in [application name](MFC42D.DLL): Ox0000005: Access Violation" when running the program. How do I resolve this issue? The problem seems as if it is embedded in a Microsoft DLL.
sriley7Asked:
Who is Participating?
 
Jaime OlivaresSoftware ArchitectCommented:
a typical cause is when you pass a null pointer to a Dll function where it is expected a non-null pointer.
0
 
jkrCommented:
When that infamous dialog comes up, select "Retry" to launch the debugger. Then, examine the call stack to find where *your* code invoked the faulting function and check if all the parameters are OK.
0
 
sriley7Author Commented:
The program crashes when this error occurs. It does not allow me to retry and continue inside of the debugger. A CMainFrame method calls the following statement:

MultiSelectDlg*      pMultiSelectDialog = new MultiSelectDlg(this);

The code then jumps to CWnd::SendMessageA() and stops at:

AFXWIN_INLINE LRESULT CWnd::SendMessage(UINT message, WPARAM wParam, LPARAM lParam)
{ ASSERT(::IsWindow(m_hWnd)); return ::SendMessage(m_hWnd, message, wParam, lParam); }
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Jaime OlivaresSoftware ArchitectCommented:
as a first glance appears to be that you are calling this line:

     MultiSelectDlg*      pMultiSelectDialog = new MultiSelectDlg(this);

*before* the invoking object (this) has created a window. Could you post more code around this line?
0
 
sriley7Author Commented:
Here is the beginning of the method:

LRESULT CMainFrame::OnOpenMultiSelectDlg (WPARAM wParam, LPARAM lParam)
{      
      BOOL bIsDSLSelect = (BOOL) wParam;
      DatasetListDlgData* pDSLdlgData = (DatasetListDlgData*)lParam;
      
      if (pDSLdlgData)
      {
            int nDSLIndex = pDSLdlgData->GetIndexDSL();
            vector<CString> vDatasetUniqueNames = pDSLdlgData->GetDatasetUniqueNames();
            vector<CString> vMemberDatasetUniqueNames = pDSLdlgData->GetMemberDatasetUniqueNames();      
            BeginWaitCursor();

            if (m_pMultiSelectDialog != NULL)
                        m_pMultiSelectDialog->SendMessage(WM_CLOSE);


            MultiSelectDlg*      pMultiSelectDialog = new MultiSelectDlg(this);

            m_pMultiSelectDialog = pMultiSelectDialog;
0
 
Jaime OlivaresSoftware ArchitectCommented:
Do you have the source code for MultiSelectDlg() constructor?
0
 
sriley7Author Commented:
I will look it up tomorrow and get back to you. I need to call it quits for the day.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
        if (m_pMultiSelectDialog != NULL)
                        m_pMultiSelectDialog->SendMessage(WM_CLOSE);


I hope you are setting m_pMultiSelectDialog to NULL when the dialog is destroyed (eg by user).

ALSO you need to do that in the constructor of the MainFrame else it could cause errors in a release build.
0
 
itsmeandnobodyelseCommented:
>>>> The problem seems as if it is embedded in a Microsoft DLL
You can force the debugger to break immediately after detecting 'access violation'. Then, you most likely would break in your code rather than in a system dll.

In VC6 you goto the Debug menu (available when debugging), sub menu Exceptions ... . Then select the 'access violation' from the list of exceptions and check the flag to break immediately.

When crashing you may examine the call stack and find out where the wrong pointer (a access violation is always caused by a invalid pointer) comes from. Look for pointer values like 0xcdcdcdcd. That is an indication that the object where the pointer is a member of was deleted. Pointers with 0x00000000 or very small numbers like 0x00000008 are an indication of using a NULL pointer. The small offsets occur if using a member of a struct or class which address is NULL, i. e. where a NULL pointer was used:

   struct XY
   {
          int x;
          int y;
   };

   XY* pxy = NULL;

   ....

   func(pxy->y);   // the address of pxy->y is 0x00000004

Regards, Alex
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.