When I have a program running.
And another program kills my programs process.
Can I detect my process being killed?
I am trying to detect my programs process being killed.
So I can clean up (deleting any memory I set aside).
Printable View
When I have a program running.
And another program kills my programs process.
Can I detect my process being killed?
I am trying to detect my programs process being killed.
So I can clean up (deleting any memory I set aside).
It depends upon how your process is being killed. If another program sends/posts WM_CLOSE message (or WM_SYSCOMMAND with SC_CLOSE option) to the main window of your program it is possible to handle closing and provide a cleanup.
In the case of TerminateProcess no cleanup is possible.
One aside note: AFAIK, the system frees all resources when the process terminates, so it is not obviously necessary to take care of allocated memory when the process ends unexpectedly.