PRB: ExitWindowsEx with EWX_LOGOFF Doesn't Work Properly

Last reviewed: April 11, 1996
Article ID: Q149690
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) version 4.0

SYMPTOMS

When an application calls ExitWindowsEx with EWX_LOGOFF in Windows 95, the application itself does not exit. Additionally, the use of the EWX_FORCE flag in conjunction with EWX_LOGOFF will cause undefined behavior.

CAUSE

It is the application's responsibility to terminate itself. However, limitations of the implementation of ExitWindowsEx in Windows 95 require that the application execute the ExitWindowsEx call and terminate itself in a particular way.

RESOLUTION

Code similar to the following will correctly perform a logoff in Windows 95:

   case IDM_LOGOFF:
      {
      DWORD    dw;
      HANDLE   hThread;

      g_hwndParent = hWnd;

      hThread = CreateThread( NULL,
                              0,
                              (LPTHREAD_START_ROUTINE)ShutdownThread,
                              (LPVOID)0,
                              0,
                              &dw);

      if(hThread)
         CloseHandle(hThread);
      }
      break;

/**************************************************************************

   ShutdownThread()

**************************************************************************/

BOOL WINAPI ShutdownThread(DWORD dwCmd) { BOOL f;

f = ExitWindowsEx(EWX_LOGOFF, 0);

//if the shutdown worked, terminate the calling app
if(f)
   {
   if(g_hwndParent)
       {
       //shutdown the calling app ASAP, don't destroy the window
       PostMessage(g_hwndParent, WM_QUIT, 0, 0);
       }
   }

return f; }

STATUS

This behavior is by design.


Additional reference words: 4.00
KBCategory: kbprg kbui kbprb
KBSubcategory: UsrCtl



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 11, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.