c++ - how to handle your windows application being force closed? -


if user decides force close application(like through task manager) there way can execute clean code before application closes? i'm coding in c++ btw

it depends on how process instructed close. possible upon graceful exit, not forcefully closed.

if process closed via terminateprocess or exitprocess, won't able perform graceful cleanup. terminateprocess how task manager , utilities sysinternals pskill end target process. exitprocess called within process not typically used exit.

if process has message pump on 1 thread (typically first thread in process) , no other threads running running code lifetimes independent of activity in thread, wm_quit message signal process should close (semantically, app should close, process might conceivably stick around while other reasons), , can run cleanup code upon receiving message. depending on needs, in windowed app might consider performing cleanup operations wm_close or wm_destroy.

if have written code in dll, there notifications can handle in dllmain allow perform last-chance cleanup (dll_process_detach), can potentially cover case of process exiting without having message pump. however, not great way perform cleanup code strictly relies on c/c++ runtime (or other dll), runtime might unloaded first.

last, graceful close control runs in winmain or main, can whatever cleanup need before either function returns, sending control windows subsystem. preferred , safest application needs.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -