How to Terminate Windows from Within QuickWin Programs

Last reviewed: July 20, 1995
Article ID: Q79382
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, version 5.1

SUMMARY

Microsoft FORTRAN version 5.1 QuickWin programs can terminate themselves, end the Windows session, and return to MS-DOS using the Windows API ExitWindows(). This is a capability that is requested by users attempting to run QuickWin programs in a batch mode from MS-DOS.

MORE INFORMATION

ExitWindows() returns a 1 if successful and a 0 (zero) if unsuccessful. The function may be unsuccessful if an application running in Windows refuses to terminate when attempting to exit Windows. The first argument should always be zero. The second argument is used to pass a return code back to MS-DOS when Windows exits.

Sample Code #1

c The following code demonstrates how to use ExitWindows() from c within a FORTRAN program. This code should be compiled and linked c as a QuickWin Windows program.

c  FL /MW WINEXIT.FOR        Sample command line for this program.

      interface to integer*2 function EXITWINDOWS
     + (dwReserved, wReturnCode)
      integer*4 dwReserved [value]
      integer*2 wReturnCode [value]
      end

      program winexit
      integer*2 ExitWindows,j

      open(1,file='test.dat')

      do i=1, 50
        write(*,*) i
        write(1,*) i
      end do

      close(1)

      j = ExitWindows(0,0)
      if (j.eq.0) print*, 'ExitWindows failed'

      end

The following batch file demonstrates how this program could be run from MS-DOS:

   win winexit
   type test.dat

Sample Code #2

c The following DOS FORTRAN program demonstrates how the QuickWin c program WINEXIT.EXE above could be called by a DOS program that c resumes execution on completion of the QuickWin program. This code c should be compiled and linked as an MS-DOS program.

c  FL  WINCALL.for    Sample command line for this program.

      interface to function spawnlp[c,varying] (mode)
      integer*2 spawnlp, mode
      end

      program wincall

      integer*2 spawnlp,i

C Spawning Windows and QuickWin program WINEXIT.EXE from MS-DOS executable.
      i=spawnlp(0,loc('d:\\windows\\win.com'c),
     +            loc('d:\\windows\\win.com'c),
     +            loc('e:\\arts\\mine\\exitwin\\WINEXIT.EXE'c),
     +            int4(0) )

C After exiting Windows, control returns to this point:
      open(2,file='test.dat')

      do j=1,50
        read(2,*) jj
        print*,jj
      end do

      close(2,status='delete')
      end


Additional reference words: kbinf 5.10
KBCategory: kbprg kbcode
KBSubcategory: FORTLngIss


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: July 20, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.