Link to home
Start Free TrialLog in
Avatar of emitchell
emitchell

asked on

Why 66 Exceptions when starting DoModal for a Dialog

I have a simple dialog app but this also is seen in my MDI app as well. I think that every time I run an MSVC app that opens a dialog box, there are a slew of First-chance exceptions.  They don't seem to do any harm but they certainly fill up the debug window!

I put a break with the debugger at the DoModal() and the debug window shows the loading of the system dlls.  Then I say go, with the next break in OnInitDialog().  At this time I get 66 messages in
the Debug window saying the following:

First-chance exception in complete.exe (KERNEL32.DLL): 0xC0000005: Access Violation.

before the break in OnInitDialog() catches.

The following is the contents of the Debug window with line lengths edited to reduce the length and the repetition deleted.  I was tracing the main message pump at the time.

OS: Windows 98, MSVC 6.0

As an aside, what's the meaning of the ...\Iomega\Tools\imghook.dll reference!


Loaded 'C:\WINDOWS\SYSTEM\USER32.DLL', no matching symb...
Loaded 'C:\WINDOWS\SYSTEM\ADVAPI32.DLL', ...
Loaded 'C:\WINDOWS\SYSTEM\GDI32.DLL',  ...
Loaded 'C:\WINDOWS\SYSTEM\KERNEL32.DLL',  ...
Loaded 'C:\WINDOWS\SYSTEM\MSVCRTD.DLL',  ...
Loaded symbols for 'C:\WINDOWS\SYSTEM\MFC42D.DLL'
Loaded 'C:\WINDOWS\SYSTEM\COMCTL32.DLL',  ...
Loaded 'C:\Program Files\Encompass\EncMon.dll',  ...
32770First-chance ... (KERNEL32.DLL): 0xC0000005: Access Violation.
Loaded 'C:\IMNnq_95\dmn95.dll', no matching symbolic information found.
First-chance ... (KERNEL32.DLL): 0xC0000005: Access Violation.
First-chance ... (KERNEL32.DLL): 0xC0000005: Access Violation.
... (66 lines of exceptions in total)
First-chance ... (KERNEL32.DLL): 0xC0000005: Access Violation.
First-chance ... (KERNEL32.DLL): 0xC0000005: Access Violation.
EDITPumpMessage: hwnd=0x0B84, msg = WM_SIZE (0x0000, 0x00000000)
Loaded 'C:\WINDOWS\SYSTEM\SHLWAPI.DLL', no match...
Loaded 'C:\WINDOWS\SYSTEM\SHELL32.DLL', no match...
Loaded 'C:\Program Files\Iomega\Tools\imghook.dll', no match...
PumpMessage: hwnd=0x07AC, msg = WM_KEYUP (0x0074, 0x883F0001)
PumpMessage: hwnd=0x07AC, msg = WM_PAINT (0x0000, 0x00000000)
Avatar of captainkirk
captainkirk

could you post your code for the dialog class??
Avatar of emitchell

ASKER

Nothing has executed in the dialog class.  I put a breakpoint at the beginning of OnInitDialog().  I've attached the actual code at the end but I removed all the contents of OnInitDialog() and still had the same symptoms.  The dialog box just contains a combobox, an edit box, some static controls and the OK and Cancel buttons.  I can send the resource file since I believe that its in the loading of this that the exceptions occur.

I've seen this behaviour before with other dialog boxes and also, I think, on my NT machine.

Jeff Richter has some coments on the First Chance Exception (MSJ, Sept 97 given MSDN discJ).  He says the following:

....
The fix comes in the form of an exception handler. When a thread raises an exception that is not handled by any exception handlers in your code, a built-in system exception handler is called. This exception handler looks specifically for access violations. If the handler sees that an access violation is raised and that this exception is an attempted write to a resource in an EXE or DLL, the system’s exception handler and the system fix the problem. The exception handler changes the page protection to PAGE_READ­WRITE. It then returns EXCEPTION_CONTINUE_EXE­CUTION so the instruction that forced the exception is re-executed. The system allocates read/write storage on-the-fly from the paging file. Then it copies the resource’s original data bytes to the newly allocated storage, and finally it maps the new storage to the same virtual address occupied by the resource. This new storage is marked as read/write so any future attempts of the application to modify the resource are successful and more access violations are not raised.
....


Remember I'm not executing any code here. It must be the Windows part that is loading the resource file.  Surely they wouldn't write anything into the resource.  And if so, why do it 66 times!


Listing of DDTestDlg.h
#if !defined(DDTestDlg_h)
#define DDTestDlg_h

////////////////////////////////////////////////////////////////////////
// CDDTestDlg dialog

class CDDTestDlg : public CDialog {

public:
      LOGFONT m_logfont;
    CDDTestDlg(CWnd* pParent = NULL);

    //{{AFX_DATA(CDDTestDlg)
    enum { IDD = IDD_DD_TEST };
    //}}AFX_DATA


    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDDTestDlg)
protected:
    virtual void DoDataExchange(CDataExchange* pDX);
    //}}AFX_VIRTUAL

protected:
    // Generated message map functions
    //{{AFX_MSG(CDDTestDlg)
    virtual BOOL OnInitDialog();
      virtual void OnOK();
      //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
private:
      CFont m_font;
    CEdit m_ebNewBox;
};

//{{AFX_INSERT_LOCATION}}

#endif // DDTestDlg_h


// DDTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "complete.h"
#include "DDTestDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDDTestDlg dialog
CDDTestDlg::CDDTestDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CDDTestDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CDDTestDlg)
    //}}AFX_DATA_INIT
}
void CDDTestDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CDDTestDlg)
    //}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDDTestDlg, CDialog)
    //{{AFX_MSG_MAP(CDDTestDlg)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDDTestDlg message handlers

BOOL CDDTestDlg::OnInitDialog()
{
    // put break point on next line
    CDialog::OnInitDialog();
    LOGFONT lf;

    return TRUE;
}
void
CDDTestDlg::OnOK()
{
      CDialog::OnOK();
}
What are you doing before the dialog is contructed and DoModal() is called?
I just constructed a standard AppWizard dialog based project that has the code at the end.  I had changed the use of the CCompleteDlg dlg; line to the CDDTest dlg2; line and used this in the call to DoModal() so that I could test one of two dialogs that I was playing with.

In fact I just went back and used the CCompleteDlg dlg2;instead of the CDDTest dlg2; line so that I was using the standard system produced by AppWizard.  The same behaviour - but 124 Exceptions this time, different dialog box!  This dialog box has 3 comboboxes, an edit box, 5 static texts and the OK and Cancel buttons.

Incidentally, when I step into the DoModal() I can get all the way to the line 327 in Dlgcore.cpp (in CWnd::CreateDlgIndirect()) where it goes into the system routine:

....
hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate,
      pParentWnd->GetSafeHwnd(), AfxDlgProc);
....

and I can't step any further.  No exceptions are generated until the thread disappears here and then all 124 come out!

code in complete.cpp
....
/////////////////////////////////////////////////////////////////////////////
// The one and only CCompleteApp object

CCompleteApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CCompleteApp initialization

BOOL CCompleteApp::InitInstance()
{
    // Standard initialization

#ifdef _AFXDLL
    Enable3dControls();
#else
    Enable3dControlsStatic();
#endif

    // CCompleteDlg dlg2;
    CDDTestDlg dlg2;
    m_pMainWnd = &dlg2;
    int nResponse = dlg2.DoModal();
    if (nResponse == IDOK) {
    }
    else if (nResponse == IDCANCEL) {
    }

    // Since the dialog has been closed, return FALSE so that we exit the
    // application, rather than start the application's message pump.
    return FALSE;
}
> Loaded 'C:\Program Files\Encompass\EncMon.dll',  ...

To me, it looks like EncMon.DLL is installing a hook that's throwing (and perhaps, handling) some exceptions.  Try removing it from your system and seeing if the problem goes away.

There's nothing wrong with 1st chance exceptions, of course, if the exception is being handled.  I don't think the article you found relates to your situation.

You should also set the debugger to break always on access violations. Then, you can look at the call stack and/or code where the exception is thrown to get a better guess of what's happening.

..B ekiM
I can't remove EncMon.dll.  I tried to rename it to EncMonRemoved.dll and I got a message box saying that EncMon.dll was being used by Windows.  What does EncMon do?  Seems like it's got something to do with Dell.

I changed the exceptions to trap always on the Access Violation and it trapped in KERNEL32. The callstack just reads

KERNEL32! bffa1004()

Here is the assembly language code that surrounds the trap address.

BFFA0FF7   mov         edi,dword ptr [esp+14h]
BFFA0FFB   or          edi,edi
BFFA0FFD   je          BFFA1006
BFFA0FFF   sub         eax,eax
BFFA1001   lea         ecx,[eax-1]
BFFA1004   repne scas  byte ptr [edi]       <- trapped here!
BFFA1006   pop         dword ptr fs:[edx]
BFFA1009   add         esp,8
BFFA100C   pop         edi
BFFA100D   jmp         BFF94DA2
BFFA1012   push        edi
BFFA1013   push        24h


Here are the registers:

 EAX = 00000000 EBX = 00000000
 ECX = FFFFFFFF EDX = 00000000
 ESI = 00008002 EDI = 00008002
 EIP = BFFA1004 ESP = 0064F274
 EBP = 00000001 EFL = 00010246
 CS = 0177 DS = 017F ES = 017F
 SS = 017F FS = 2D8F GS = 0000 OV=0
 UP=0 EI=1 PL=0 ZR=1 AC=0 PE=1 CY=0
 ST0 = +0.00000000000000000e+0000

1. Is your constuctor is called successfully ?

2. Check the messages which are called before WM_InitDialog.
More news that I think solves the question.  I called Dell and they had me look at the sysconfig - startup tab.  In there checked was the running of EncMontor.  Unchecking that and a few other boxes that I had neve heard of solved the problem.  That was how the Iomega dll got into the act. They start up an Iomega Watch task without telling me and certainly without my leave!

When I run the VC app now, there are no Access Violations.

How do I award the A for a fine job done!
> running of EncMontor
> Iomega Watch task

what are these terms ??
I have a Dell machine just about 14 months old.  If I run MSconfig.exe in the C:\WINDOWS\SYSTEM directory there is a dialog box put up, one of the pages of which is labelled Startup.  There are about 40 check boxes, of which EncMonitor was checked.  The reference to this was the file C:\Program Files\Encompass\Monitor.exe.  I've no idea what it does but the Encompass directory contains directories ATT_App, Channels, Sounds, Ziff, ...  Presumably something put there by Dell.

The Iomega Watch task was put into the same startup page, presumably when I installed my Zip drive.  That's another dll that was being loaded  withou my knowledge.

I sent a report to Dell telling them of the trouble they were causing so I'll report back if they say anything meaningful.
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial