In order to find the correct fix for bug 18753, I've been examining the shutdown process on Windows. I have written a program that logs the messages sent to it, and I've run it on Windows 7. What I found was that a shutdown produces the following sequence of events: * We get a 0x3b message. DefWindowProc sends a WM_QUERYENDSESSION message. We return 1, allowing the session to end. * We get another 0x3b message, which leads to a WM_ENDSESSION. * Nothing else happens, but for some reason the program exits.
I added a trace after the message loop returns to see if the program gets a WM_QUIT. It doesn't.
Apparently, my test program was killed.
I tried changing the window proc so that it loops infinitely when it gets WM_ENDSESSION. Windows 7 sees this as "blocking shutdown". (Naturally, it responds the same way if I return 0 from WM_QUERYENDSESSION.)
This leads me to believe that Windows 7, when shutting down, immediately kills any process that returns from a WM_ENDSESSION message.
Does that seem sane?
I've posted my test program (source code and .exe file) at http://madewokherd.nfshost.com/msgtest.zip, and I'd like to hear if other Windows versions behave the same way Windows 7 does.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Vincent Povirk wrote:
In order to find the correct fix for bug 18753, I've been examining the shutdown process on Windows. I have written a program that logs the messages sent to it, and I've run it on Windows 7. What I found was that a shutdown produces the following sequence of events:
- We get a 0x3b message. DefWindowProc sends a WM_QUERYENDSESSION
message. We return 1, allowing the session to end.
- We get another 0x3b message, which leads to a WM_ENDSESSION.
- Nothing else happens, but for some reason the program exits.
I added a trace after the message loop returns to see if the program gets a WM_QUIT. It doesn't.
Apparently, my test program was killed.
I tried changing the window proc so that it loops infinitely when it gets WM_ENDSESSION. Windows 7 sees this as "blocking shutdown". (Naturally, it responds the same way if I return 0 from WM_QUERYENDSESSION.)
This leads me to believe that Windows 7, when shutting down, immediately kills any process that returns from a WM_ENDSESSION message.
Does that seem sane?
I've posted my test program (source code and .exe file) at http://madewokherd.nfshost.com/msgtest.zip, and I'd like to hear if other Windows versions behave the same way Windows 7 does.
OS | Terminated on return from WM_ENDSESSION or 0x3B Windows Vista | yes Windows XP | yes Windows 98 | yes
None of these returned from GetMessage, and no atexit handlers were called. Windows 98 did not send the 0x3B message, but terminated the program after the message handler returned from WM_ENDSESSION.
Windows 98 doing this says Windows NT 4.0 would have done this.
I don't have Windows NT 3.1 to test with, but I think it would have done the same.
Some references: http://blogs.msdn.com/michen/archive/2008/04/04/Application-termination-when-user-logs-off.aspx http://blogs.msdn.com/oldnewthing/archive/2008/04/21/8413175.aspx
Basically, Windows calls TerminateProcess on the process when all of its window message loop threads have returned from the WM_ENDSESSION (or wrapping 0x3B) message.
On Sun, Nov 29, 2009 at 1:21 AM, Ben Peddell klightspeed@netspace.net.au wrote:
<stuff>
So the behavior I'm seeing matches other versions of Windows and is documented. Excellent. Thanks.