🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #13326

Re: Console mode app shutdown?

#13326
From: Bob Gonder
Date: Thu, 16 Oct 2003 09:39
68 lines
3175 bytes
Remy Lebeau (TeamB) wrote:

>"Jeff Douglass" <.> wrote in message
>news:3f8dd4e4$1@newsgroups.borland.com...
>> However if I close the app using End Process from withing
>> the task manager my break routine is not getting called and
>> therefor the app's shutdown cleanup stuff I trigger from within
>> my break handler does not get called. Any ideas on what is
>> going on? What is best way to handle the closing of a console
>> mode app via the Task Manager?
>
>There isn't any.  The "End Process" feature is a brute-force termination.
>You can't prevent or detect it.

It looks like you _can_ detect it.
I just added a log to my handler, and it writes a 2 (CTRL_CLOSE_EVENT)
when I EndProcess from the XPHome Task Manager.

The Code:
	SetConsoleCtrlHandler( &CtrlHandler, TRUE);

static BOOL _stdcall CtrlHandler(DWORD fdwCtrlType)
{
#if LogHandler
	DWORD	written;
	HANDLE	h =
CreateFile("Log.Log",GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_FLAG_WRITE_THROUGH,NULL);
	if( h != INVALID_HANDLE_VALUE )
	{	SetFilePointer(h,0,NULL,FILE_END);

WriteFile(h,&fdwCtrlType,sizeof(fdwCtrlType),&written,NULL);
		CloseHandle( h );
	};
#endif

    switch (fdwCtrlType)
    { 
	/* Handle the CTRL+C signal. */ 
	case CTRL_C_EVENT: 
		push_key(CtrlC);	/*  pass Ctrl-C to app  */
		return TRUE;
 
	/* CTRL+CLOSE: confirm that the user wants to exit. */
	/* Ctrl_Close _needs_ to return False because I don't want
	 a dialog poping up.
	Other events return True because I handled them this time,
	 and disabled myself so subsequent events will be false.*/
	case CTRL_CLOSE_EVENT:
		SetConsoleCtrlHandler( &CtrlHandler, FALSE);
		return FALSE;
 
	case CTRL_LOGOFF_EVENT:
	case CTRL_SHUTDOWN_EVENT: 
	case CTRL_BREAK_EVENT:
		SetConsoleCtrlHandler( &CtrlHandler, FALSE);
		return TRUE;	/*  we handled it this time, say so.*/
	default:
		return FALSE;
    }; 
}
The values.
#define CTRL_C_EVENT        0
#define CTRL_BREAK_EVENT    1
#define CTRL_CLOSE_EVENT    2
// 3 is reserved!
// 4 is reserved!
#define CTRL_LOGOFF_EVENT   5
#define CTRL_SHUTDOWN_EVENT 6
Technical Details
Message-ID: <2nosovsi32n8cj4man9n845891i0smm7c3@4ax.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeeds.sol.net!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f8dd4e4$1@newsgroups.borland.com> <3f8dd7f8$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,54d8f3a9e4ffc94e
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-10-16 02:42:17 PST
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Console mode app shutdown?
Date: Thu, 16 Oct 2003 02:39:00 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <2nosovsi32n8cj4man9n845891i0smm7c3@4ax.com>
References: <3f8dd4e4$1@newsgroups.borland.com> <3f8dd7f8$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.91/32.564
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.31.164.97
X-Trace: newsgroups.borland.com 1066297142 67.31.164.97 (16 Oct 2003 02:39:02 -0700)
Lines: 70
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeeds.sol.net!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail