Re: Using SetConsoleCtrlHandler



Windows is not very good at handling this sort of asynchronous interrupt on
a single thread Emmanuel (i.e. similar to UNIX signals, or even VMS ASTs)

The question has been asked before:
http://groups.google.ie/group/microsoft.public.win32.programmer.kernel/browse_frm/thread/608ad10204f76515/1e175f06dca6106f?hl=en#1e175f06dca6106f

I've even found myself in the same boat in trying to port a language, and
its framework, to the Windows O/S. In the end, I suspended the thread, read
its context, redirected it to a point that would generate the required
exception, and then released it. Surprisingly, it worked OK in practice
(although not on Alpha AXP H/W) but there were a few issues with win32 api
calls that had to be addressed (mentioned in that old thread)

Tony Proctor

"Emmanuel Stapf [ES]" <manus@xxxxxxxxxxxxxxxxx> wrote in message
news:uQhAUi9pHHA.1144@xxxxxxxxxxxxxxxxxxxxxxx
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 ){ }
}


.



Relevant Pages

  • Re: Increasing wireless internet signal between buildings
    ... block/attentuate radio signals.. ... Do your office windows open, ... The ceramic coatings pass RF easily. ... office buildings nowadays (not a film, but something in the glass to ...
    (alt.internet.wireless)
  • Re: Cheap Oscilloscope
    ... >pipe TV signals in too, what kind of frequencies are they at? ... you might want to check out my Daqarta ... which rules out Windows systems later than Win9x. ... Having a real-time spectrum analyzer is really useful ...
    (sci.electronics.basics)
  • Re: Why wireless card needs to be disable before recording
    ... windows zeroconf will search for a wireless ... > signal constantly if the card is enabled. ... Is this a built-in Windows program? ... search for signals, click on one, then "modify" the default profile to ...
    (rec.audio.pro)
  • Cant connect to home wireless station
    ... Windows displays my wireless base station as being available for ... I get a dialog saying that Windows is unable to ... It will connect to other wireless signals in the ... is a macbook running windows via bootcamp. ...
    (comp.sys.mac.comm)
  • Re: OS recomendations for stratum 2 clocks
    ... signals through 70 cm thick walls out of old fashioned solid bricks, and my office is in the basement, the buildings around are 5 floors high. ... For the far away MSF I get only a constant signal in one room without windows to the west. ...
    (comp.protocols.time.ntp)