How does Windows close the program when you turn off the computer?

My application causes some strange errors if you turn off the computer while my application is running.

Sometimes a message (address) memory cannot be “read” , sometimes it cannot be “write” .

Shutting down the application in the usual way does not generate such messages.

How can I simulate “closing windows” so that I can debug my application? How can I find out what the application is trying to do, which it cannot?

+7
c ++ windows wxwidgets
source share
1 answer

When Windows wants to shut down, it sends a series of events to the application; e.g. WM_ENDSESSION and WM_QUIT . You can process them in the message handler that you use; in general, the application will have to respond appropriately and quickly to these messages, otherwise the OS will simply terminate the application in any case. I'm not sure what default processing wxwidgets offers in this regard. Inclusion in them will help in diagnosing the application error itself.

There are a few things you could try to do:

  • the shutdown sequence will not be easy to model (if at all) - a lot happens during shutdown; the exact state and situation is difficult to imitate as a whole.
  • From the point of view of diagnosing the state of the application, before shutting down, you can try to process WM_QUERYENDSESSION and answer FALSE to prevent it from closing (with newer versions of Windows you can no longer stop the shutdown, so it may not work depending on the platform you are on) .
  • You can also try to test the application’s immediate response to the WM_ENDSESSION message by sending it to WM_ENDSESSION (for example, via PostMessage ) with the corresponding data, as described in MSDN.

For terminal applications; You can also connect signals ( SIGKILL I reckon) if necessary. See the Microsoft Link for more details. You can also use SetConsoleCtrlHandler . But since you are using a toolbox, it would be better to use messages sent to the application already.

+5
source share

All Articles