Article View: borland.public.cppbuilder.nativeapi
Article #1469SetConsoleCtrlHandler not processing close messages
From: Mike Collins
Date: Wed, 08 Aug 2007 12:11
Date: Wed, 08 Aug 2007 12:11
85 lines
3564 bytes
3564 bytes
Hi all, posted a few days ago about a console application i was writing,
specifically processing messages within. I found some code that remy had
posted and tried to impliment it. The code seems to work but when i hit
Ctrl+Break the console application does not terminate. The
SetConsoleCtrlHandler callback seems to be called and the PostQuitMessage()
is sent but the console app does not terminate. Thus i can't find any way
to drop out of the message processing and my console app does not clean up
after it's self. My code looks like this:
BOOL CALLBACK HandlerRoutine(DWORD dwCtrlType)
{
PostQuitMessage(0);
return TRUE;
}
//---------------------------------------------------------------------------
int main(int argc, char* argv[])
{
if ((argc > 1)&&(stricmp(argv[1], "/?") == 0))
{
// Show help options
...
}
else
{
int iPort = DEF_SERVER_PORT_NO;
int iServerType = DEF_SERVER_TYPE;
int iThreadCache = DEF_THREAD_CACHE_COUNT;
int iReturnErr = DEF_ERROR_RETURN_VALUE;
AnsiString szExponent, szModulus;
int iRtn = 0;
TWebMod *WebMod = NULL;
try
{
try
{
SetConsoleCtrlHandler(&HandlerRoutine, TRUE);
WebMod = new TWebMod(NULL);
WebMod->InitialiseSocket(iPort, iServerType, iThreadCache,
szExponent, szModulus);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) //&&(!bEnd))//&&(ch
!= 'x'))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
switch (msg.message)
{
case WM_SYSCOMMAND : if ((msg.wParam & 0xFFF0) !=
SC_CLOSE)
break;
// fall though to the next
block...
case WM_CLOSE : if (PeekMessage(&msg, NULL,
WM_QUIT, WM_QUIT, PM_NOREMOVE) == 0)
PostQuitMessage(0);
break;
}
}
}
catch (...)
{
printf("\t\t\t ERROR");
iRtn = iReturnErr;
}
}
__finally
{
if (WebMod)
{
delete WebMod;
WebMod = NULL;
}
SetConsoleCtrlHandler(&HandlerRoutine, FALSE);
}
return iRtn;
}
}
Any pointers would be greatfully recieved.
Mike C
Technical Details
Message-ID:
<46bae4a2$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!194.25.134.62.MISMATCH!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d5cddcb589c8cc6f,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Mike Collins" <its@TheBottomOfThePost> Newsgroups: borland.public.cppbuilder.nativeapi Subject: SetConsoleCtrlHandler not processing close messages Date: Wed, 8 Aug 2007 12:11:19 -0000 Lines: 87 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.3959 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4073 NNTP-Posting-Host: 89.240.177.224 Message-ID: <46bae4a2$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1186653346 89.240.177.224 (9 Aug 2007 02:55:46 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!194.25.134.62.MISMATCH!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail