Question

Is there a way to call a function at termination(clicking on the red X of the console) of an non-Object-oriented console application(simple main program)?

Maybe to catch the message of the red X and handle it then...

Thanks!

Was it helpful?

Solution

When you are on Windows and have a console application running inside the normal console window, and then click on the Close Button ([X]) this will generate a CTRL_CLOSE_EVENT.

You can handle these by installing a Console Event Handler with the SetConsoleCtrlHandler Win32 API function.

OTHER TIPS

You can try using atexit():

http://www.cplusplus.com/reference/cstdlib/atexit/

Or maybe a destructor of a global object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top