I am using the method suggested in the KBase of how to programmatically
exit from a MFC application:
void ExitApp()
{
// same as double-clicking on main window close box
ASSERT(AfxGetApp()->m_pMainWnd != NULL);
AfxGetApp()->m_pMainWnd->SendMessage(WM_CLOSE);
}
When I am debugging my application and call this function like:
CMylistView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
...
if( Error() )
{
ExitApp();
}
}
I would get an "Access Violation" in MFC42D.DLL in
WINFRM.CPP line 768
...
// give view a chance to save the focus (CFormView needs this)
if (pView != NULL)
pView->OnActivateFrame(WA_INACTIVE, this);
...
This code is called after it has went through the destructor of the
view, frame, and document respectively.
The following is in the output window:
First-chance exception in ApprUtil.exe (KERNEL32.DLL): 0xC0000005:
Access Violation.
First-chance exception in ApprUtil.exe (MFC42D.DLL): 0xC0000005: Access
Violation.
I would appreciate any suggestion or pointers that you may have. Thanks
in advance!!
PS: I am using VC 4.2 under window NT 3.51.
An Tay Nguy
Try using PostMessage() instead of SendMessage()
---------------------------------------------
Craig Henderson
---------------------------------------------
Programmer's tips and *free* software at
http://www.kc-imaging.demon.co.uk
---------------------------------------------
Remove nospam from email address for replies
> Hi all!!
>
> I am using the method suggested in the KBase of how to
> programmatically
> exit from a MFC application:
>
> void ExitApp()
> {
> // same as double-clicking on main window close box
> ASSERT(AfxGetApp()->m_pMainWnd != NULL);
> AfxGetApp()->m_pMainWnd->SendMessage(WM_CLOSE);
> }
>
> When I am debugging my application and call this function like:
>
> CMylistView::OnInitialUpdate()
> {
> CListView::OnInitialUpdate();
> ...
> if( Error() )
> {
> ExitApp();
> }
> }
>
> I would get an "Access Violation" in MFC42D.DLL in
>
> WINFRM.CPP line 768
> ...
> // give view a chance to save the focus (CFormView needs this)
> if (pView != NULL)
> pView->OnActivateFrame(WA_INACTIVE, this);
> ...
>
> This code is called after it has went through the destructor of the
> view, frame, and document respectively.
>
> The following is in the output window:
>
> First-chance exception in ApprUtil.exe (KERNEL32.DLL): 0xC0000005:
> Access Violation.
> First-chance exception in ApprUtil.exe (MFC42D.DLL): 0xC0000005:
> Access
> Violation.
>
> I would appreciate any suggestion or pointers that you may have.
> Thanks
> in advance!!
>
> PS: I am using VC 4.2 under window NT 3.51.
>
> An Tay Nguy
An Tay Nguy,
you have tried to close the mainframe before it finshed
creating, maybe tring PostMessage() instead SendMessage() will do in
this case
Ya'eer
>An Tay Nguy wrote:
>
>> Hi all!!
>>
>>
>> When I am debugging my application and call this function like:
>>
>> CMylistView::OnInitialUpdate()
>> {
>> CListView::OnInitialUpdate();
>> ...
>> if( Error() )
>> {
>> ExitApp();
>> }
>> }
>>
>> I would get an "Access Violation" in MFC42D.DLL in
>>
I suggest checking/responding to the error at a different location, but if
you have not other choice, than try calling AfxAbort( );
You must take in account: stack and memory allocation will not be released
by this approach.
Tal J. Rosen
t...@security7.com
>I try your code and it's work fine
>i use visual c++ 5 and win 95
>
>An Tay Nguy wrote:
>
>> Hi all!!
>>
>> CMylistView::OnInitialUpdate()
>> {
>> CListView::OnInitialUpdate();
>> ...
>> if( Error() )
>> {
>> ExitApp();
>> }
>> }
While I've never seen a problem like this, I would also suggest that
it is hardly ever appropriate to exit an application on an error.
This paradigm suggests that you know exactly the implications *to the
user* of exiting. I have found that it is hardly ever appropriate to
exit a Windows program on an error. Worse still, there are
third-party library vendors whose libraries tend to do this and
equivalent horrible things. Generally, you should pop up an error box
and return to a neutral state so the user can do something more
useful. There are few things more annoying than a program that
spontaneously exits. I consider this a holdover from the days of
DOS-based mini-apps and a very inappropriate paradigm for a
Windows-based program.
joe
Joseph M. Newcomer
newc...@flounder.com
http://www3.pgh.net/~newcomer