Using SetConsoleCtrlHandler
- From: "Emmanuel Stapf [ES]" <manus@xxxxxxxxxxxxxxxxx>
- Date: Tue, 05 Jun 2007 18:18:06 -0700
Hi,
I've a console single threaded application and I'm trying to catch a Ctrl+C. No
matter if I use SetConsoleCtrlHandler or a signal handler, my code to handle
this gets called in another thread. Is there a way to have the handler called
from the main thread?
In the code below, simply comment the call to `signal' or to
`SetConsoleCtrlHandler' to observe the similar behavior. On Unix, using
`signal', it is called from the same thread.
Thanks for any highlight,
Manu
PS: this is shown by the code:
#include <windows.h>
#include <stdio.h>
#include <signal.h>
BOOL CtrlHandler( DWORD fdwCtrlType )
{
switch( fdwCtrlType ) {
case CTRL_C_EVENT:
printf( "Ctrl-C event\n\n" );
return TRUE;
default:
return FALSE;
}
}
void handler (int sig) {
printf ("From Signal\n");
signal (SIGINT, handler);
}
void main( void )
{
signal (SIGINT, handler);
//SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE );
printf("Use Ctrl+C to see what is going on.\n" );
while( 1 ){ }
}
.
- Follow-Ups:
- Re: Using SetConsoleCtrlHandler
- From: Tony Proctor
- Re: Using SetConsoleCtrlHandler
- From: Gary Chanson
- Re: Using SetConsoleCtrlHandler
- Prev by Date: Re: Loading DLL
- Next by Date: Re: Using SetConsoleCtrlHandler
- Previous by thread: Network/Internet state change notification
- Next by thread: Re: Using SetConsoleCtrlHandler
- Index(es):
Relevant Pages
|