I apparently can detect my c++ program is closed by following code
static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType)
{
switch (dwCtrlType)
{
case CTRL_C_EVENT: // Ctrl+C
case CTRL_BREAK_EVENT: // Ctrl+Break
case CTRL_CLOSE_EVENT: //case CTRL_CLOSE_EVENT:
case CTRL_LOGOFF_EVENT: // User logs off.
case CTRL_SHUTDOWN_EVENT: // System is shutting down.
}
}
I want to detect and know whether my program is closed by unknown so that can run few last bits my code so smooth closing. .