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

1) With signal():
#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.04865 seconds with 9 queries