AfxMessageBox throws first chance exception |
|
Author |
Message |
Naran

|
Posted: Fri Aug 20 04:13:01 CDT 2004 |
Top |
MFC >> AfxMessageBox throws first chance exception
Hi,
I have a problem in my MFC MDI app with loading files which are of the
wrong format. (When using "All Files" option in the load dialog.)
I try to catch files with the wrong extension in OnOpenDocument and
show an afxmessagebox. However, I get an access violation when trying
to do so. The same problem occurs in my doc's serialize function,
where I use AfxThrowException to catch files of the wrong format.
AfxThrowException also tries to display a message box and I get the
same problem.
I have stepped through the code - I get to here in
CWinApp::DoMessageBox in the file APPUI1.cpp:
int nResult =
::MessageBox(hWnd, lpszPrompt, pszAppName, nType);
Stepping into that line gives the exception. When I OK the exception
error box, the stack trace jumps to my view's overridden OnPaint
function, which has a pointer to the document which seems to be
invalid.
Any ideas what might be going on?
Thanks,
Mike
Visual Studio235
|
|
|
|
 |
AdrianFoobarSoftwarecom

|
Posted: Fri Aug 20 04:13:01 CDT 2004 |
Top |
MFC >> AfxMessageBox throws first chance exception
I think what is happening is that when the Open File dialog closes, it leaves
an area of your window waiting to be redrawn. When the message box is
displayed, the app notices it has some time and so it processes the WM_PAINT
message to redraw the window.
So, you need to look at your file open code and OnPaint function rather than
this MessageBox call - you will need to ensure that the OnPaint can cope with
the fact that your OnOpenDocument function has not completed.
A.
> Hi,
> I have a problem in my MFC MDI app with loading files which are of the
> wrong format. (When using "All Files" option in the load dialog.)
>
> I try to catch files with the wrong extension in OnOpenDocument and
> show an afxmessagebox. However, I get an access violation when trying
> to do so. The same problem occurs in my doc's serialize function,
> where I use AfxThrowException to catch files of the wrong format.
> AfxThrowException also tries to display a message box and I get the
> same problem.
>
> I have stepped through the code - I get to here in
> CWinApp::DoMessageBox in the file APPUI1.cpp:
>
> int nResult =
> ::MessageBox(hWnd, lpszPrompt, pszAppName, nType);
>
> Stepping into that line gives the exception. When I OK the exception
> error box, the stack trace jumps to my view's overridden OnPaint
> function, which has a pointer to the document which seems to be
> invalid.
>
> Any ideas what might be going on?
> Thanks,
> Mike
>
|
|
|
|
 |
Mike

|
Posted: Fri Aug 20 11:55:22 CDT 2004 |
Top |
MFC >> AfxMessageBox throws first chance exception
Hi Adrian,
I think you're on the right track - everything is OK if i take
references to the document out of the relevant OnPaint and OnDraw
functions.
So now i want to run those parts conditionally, ie. only if I have a
valid document pointer. However, I'm not sure how to check whether my
view's pointer to the document is valid. It is not always null when it
fails. How can I check that the pointer I have is for a valid
document?
Thanks,
Mike
On Fri, 20 Aug 2004 02:13:01 -0700, Adrian ~ FoobarSoftware.com
>I think what is happening is that when the Open File dialog closes, it leaves
>an area of your window waiting to be redrawn. When the message box is
>displayed, the app notices it has some time and so it processes the WM_PAINT
>message to redraw the window.
>So, you need to look at your file open code and OnPaint function rather than
>this MessageBox call - you will need to ensure that the OnPaint can cope with
>the fact that your OnOpenDocument function has not completed.
>
>A.
>
>
>> Hi,
>> I have a problem in my MFC MDI app with loading files which are of the
>> wrong format. (When using "All Files" option in the load dialog.)
>>
>> I try to catch files with the wrong extension in OnOpenDocument and
>> show an afxmessagebox. However, I get an access violation when trying
>> to do so. The same problem occurs in my doc's serialize function,
>> where I use AfxThrowException to catch files of the wrong format.
>> AfxThrowException also tries to display a message box and I get the
>> same problem.
>>
>> I have stepped through the code - I get to here in
>> CWinApp::DoMessageBox in the file APPUI1.cpp:
>>
>> int nResult =
>> ::MessageBox(hWnd, lpszPrompt, pszAppName, nType);
>>
>> Stepping into that line gives the exception. When I OK the exception
>> error box, the stack trace jumps to my view's overridden OnPaint
>> function, which has a pointer to the document which seems to be
>> invalid.
>>
>> Any ideas what might be going on?
>> Thanks,
>> Mike
>>
|
|
|
|
 |
Mike

|
Posted: Fri Aug 20 12:47:19 CDT 2004 |
Top |
MFC >> AfxMessageBox throws first chance exception
Aha.
It seems that as I hadn't initialised my m_pDoc members to NULL, they
were 0xcdcdcd by default, thus failing the
if (m_pDoc==NULL)
test.
Fixed.
>Hi Adrian,
>I think you're on the right track - everything is OK if i take
>references to the document out of the relevant OnPaint and OnDraw
>functions.
>So now i want to run those parts conditionally, ie. only if I have a
>valid document pointer. However, I'm not sure how to check whether my
>view's pointer to the document is valid. It is not always null when it
>fails. How can I check that the pointer I have is for a valid
>document?
>Thanks,
>Mike
|
|
|
|
 |
|
|