HOWTO: Exit Windows from a Visual Basic 4.0 Application

ID: Q129637


The information in this article applies to:


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 query words: 4.00 terminate end quit stop vb4win vb432


Keywords          : 
Version           : 4.0
Platform          : WINDOWS 
Issue type        : 

Last Reviewed: June 9, 1999