Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exit from MFC application

256 views
Skip to first unread message

An Tay Nguy

unread,
Aug 12, 1997, 3:00:00 AM8/12/97
to

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

Craig Henderson

unread,
Aug 13, 1997, 3:00:00 AM8/13/97
to

In article <33F0A3...@pipe.nova.ca>, an-ta...@pipe.nova.ca says...

> 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

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

Yaeer Kidron

unread,
Aug 14, 1997, 3:00:00 AM8/14/97
to An Tay Nguy

An Tay Nguy wrote:

> 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


Tal J. Rosen

unread,
Aug 26, 1997, 3:00:00 AM8/26/97
to

>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


Joseph M. Newcomer

unread,
Aug 30, 1997, 3:00:00 AM8/30/97
to

On Mon, 25 Aug 1997 17:37:23 +0300, LIFSHITS ILYA
<il...@deltathree.com> wrote:

>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

0 new messages