|
From: Tatsuro M. <tma...@ya...> - 2010-01-29 06:54:08
|
Hello
I have found web page in written Japanese.
It was written that SIGINT is not easy to handle in console applications.
However, there shows a way to use SetConsoleCtrlHandler function.
#***************
#include <windows.h>
#include <wincon.h>
#include <iostream>
//handler function
BOOL handler(DWORD ctrlChar){
if(CTRL_C_EVENT == ctrlChar){
std::cout<< "Ctrl+C pressed"<< std::endl;
return FALSE;
}
int main(void){
::SetConsoleCtrlHandler(handler, TRUE);
while(true)
::Sleep(100);
return 0;
}
#*********
prototype of handler
BOOL WINAPI HandlerRoutine(DWORD dwCtrlType);
#***************
dwCtrlType
CTRL_C_EVENT Receives Cntl+C
CTRL_BREAK_EVENT Receives Cntl+BREAK
CTRL_CLOSE_EVENT Console is closed by a user
CTRL_LOGOFF_EVENT Receives a signal which is sent from the system
to all console processes because user tries to log off
CTRL_SHUTDOWN_EVENT Receives a signal which is sent from the system
to all console processes because user tries to shut down
#**************
MSDN page in English
http://msdn.microsoft.com/en-us/library/ms686016(VS.85).aspx
Are the above helpful?
Regards
Tatsuro
--- Ethan Merritt <merritt@u.washington.edu> wrote:
> On Thursday 28 January 2010 15:33:48 Tatsuro MATSUOKA wrote:
> > Hello
> >
> > I have remembered that Benjamin have posted concerning issue of ctrl+c on gnuplot.exe for
> windows.
> >
> > http://old.nabble.com/MSWin-issues-holding-up-4.4.rc1-td25793940.html#a26015183
> >
> > ****************
> > --- gnuplot-4.3.0-2009-07-08-orig/src/plot.c 2009-09-20 20:16:47 +0200
> > +++ gnuplot-4.3.0-2009-07-08/src/plot.c 2009-10-18 13:06:08 +0200
> > @@ -684,7 +684,11 @@
> > setmatherr(purec_matherr);
> > #endif
> >
> > +#if defined(WGP_CONSOLE)
> > + (void) signal(SIGINT, SIG_IGN);
> > +#else
> > (void) signal(SIGINT, (sigfunc) inter);
> > +#endif
> >
> > #ifdef SIGPIPE
> > /* ignore pipe errors, this might happen with set output "|head" */
> > ******************
> >
> > The above seems not to be applied yet.
>
> That would cause the program to ignore ctrl-c.
> It would be better to fix the signal-handling routine so that it
> responds to ctrl-c correctly.
>
> Does someone know the history of this problem?
> Did ctrl-c work on Windows in older versions of gnuplot?
> If so, when did it break?
>
> --
> Ethan A Merritt
>
--------------------------------------
Get the new Internet Explorer 8 optimized for Yahoo! JAPAN
http://pr.mail.yahoo.co.jp/ie8/
|