?
Solved

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

Posted on 2007-10-17
11
Medium Priority
?
2,519 Views
Last Modified: 2013-12-14
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.
0
Comment
Question by:sriley7
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 20098533
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
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 672 total points
ID: 20098557
a typical cause is when you pass a null pointer to a Dll function where it is expected a non-null pointer.
0
 

Author Comment

by:sriley7
ID: 20098620
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20098644
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
 

Author Comment

by:sriley7
ID: 20098658
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
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20098727
Do you have the source code for MultiSelectDlg() constructor?
0
 

Author Comment

by:sriley7
ID: 20098779
I will look it up tomorrow and get back to you. I need to call it quits for the day.
0
 
LVL 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 664 total points
ID: 20099063
        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
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 664 total points
ID: 20099259
>>>> 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
 
LVL 1

Expert Comment

by:Computer101
ID: 20295276
Forced accept.

Computer101
EE Admin
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question