View Single Post
Old 04 June 2016, 14:42   #3
BlankVector
Registered User
 
Join Date: Jun 2012
Location: Paris, France
Posts: 148
It is possible to handle such exit event.

1) With signal():
Code:
#include <signal.h>

void __cdecl myhandler(int sig)
{
	printf("Good bye\n");
}

...
	signal(SIGINT, myhandler); // Ctrl+C
	signal(SIGBREAK, myhandler); // Close console
I have tested the above, it works fine.

2) Using the low level SetConsoleCtrlHandler() to catch CTRL_BREAK_EVENT (untested).
BlankVector is offline  
 
Page generated in 0.05792 seconds with 9 queries