Microsoft KB Archive/129637

-

The information in this article applies to:


 * Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 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
 Start a new project in Visual Basic. Form1 is created by default.  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   Add the following code to the Form_Click event:   ExitWindows EWX_LogOff, &HFFFFFFFF  Save the project for future use, if desired. Choose Make EXE File... from the File menu to compile the program. Close all running instances of Visual Basic and run the compiled EXE. Click the Form. Windows will close all running applications and log the user off from the current Windows session.</li></ol>

Additional query words: 4.00 terminate end quit stop vb4win vb432

Keywords :

Version : 4.0

Platform : WINDOWS

Issue type : kbhowto