HOWTO: Exit Windows from a Visual Basic 4.0 Application

Last reviewed: November 17, 1997
Article ID: Q129637
4.00 WINDOWS kbprg

The information in this article applies to:

  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 32-bit only, for Windows, version 4.0

SUMMARY

This article shows by example how to exit Windows from a Visual Basic version 4.0 application.

MORE INFORMATION

When you make calls to Windows APIs from the 32-bit version of Microsoft Visual Basic version 4.0, note that the functions being called reside in the 32-bit DLLs of the Win32 Operating System. Therefore, it is no longer possible to call the ExitWindows API function directly from Visual Basic because there is no ExitWindows entry point in USER32.EXE on Win32 Operating Systems. This is a change in behaviour from previous versions of Visual Basic.

Under Win32 Operating Systems, ExitWindows is a C++ macro in the WINUSER.H header file that maps to the ExitWindowsEx API:

   #define EWX_LOGOFF 0
   #define ExitWindows(dwReserved,Code) ExitWindowsEx(EWX_LOGOFF, _
      0xFFFFFFFF)

When calling this function from the 32-bit version of Visual Basic version 4.0, you must use the equivalent Declare statement.

Step-by-Step Example

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add the following code to the General Declarations portion of Form1:

    Const EWX_LogOff As Long = 0

       Private Declare Function ExitWindows Lib "User32" _
          Alias "ExitWindowsEx" _
          (ByVal dwOptions As Long, ByVal dwReserved As Long) As Long
    
    

  3. Add the following code to the Form_Click event:

    ExitWindows EWX_LogOff, &HFFFFFFFF

  4. Save the project for future use, if desired.

  5. Choose Make EXE File... from the File menu to compile the program.

  6. Close all running instances of Visual Basic and run the compiled EXE.

  7. Click the Form. Windows will close all running applications and log the user off from the current Windows session.


Additional reference words: 4.00 terminate end quit stop vb4win vb432
KBCategory: kbprg
KBSubcategory: APrgOther
Keywords : APrgOther kbprg
Version : 4.0
Platform : WINDOWS


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: November 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.