Win32 console app shutdown issues
I'm trying to capture the close event for a console window. Currently the code uses SetConsoleCtrlHandler() which sets a handler that Windows calls when certain events happen.
Big problem is that this spawns another thread according to the debugger. So if you call your shutdown function from the handler function, it will then return to main where you would also call shutdown (for a normal app termination).
This means you are calling shutdown twice. I thought it was perfectly valid to call delete on NULL pointers and it's not bailing on that but it bails after the return 0 in main.
I'm getting a DebugBreak() upon exiting the application in debug mode. No memory leaks or issues but it throws an exception. There is a small blurb in the docs about throwing an exception in debug mode but this applies to capturing CTRL-C which I'm not doing.
Any ideas? I'm just trying to be a well-behaved app and clean up even if the user presses the close button on the console window.
I'm seriously about to register my window handle with Windows to tap into the message loop scheme of things.
Console apps are a pain.