Win32 Console Programming Question
C / C++ / MFC
3
Posts
3
Posters
0
Views
1
Watching
-
How can i handle unexpected exits to the program (i.e. a user hits ctrl+break) so that i can clean up memory allocated? Thanks!
See
signal
. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
How can i handle unexpected exits to the program (i.e. a user hits ctrl+break) so that i can clean up memory allocated? Thanks!
I think this should server your purpose: BOOL WINAPI ConsoleHandler(DWORD dwCtrlType) { switch(dwCtrlType) { case CTRL_CLOSE_EVENT: case CTRL_C_EVENT: case CTRL_BREAK_EVENT: case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: { // Cleanup code return TRUE; } } return FALSE; } int _tmain( ...) { SetConsoleCtrlHandler(ConsoleHandler, TRUE); // // Other code goes here }