Microsoft KB Archive/64588

COBOL Program to Determine Current Mode (Real or Protected)

PSS ID Number: Q64588 Article last modified on 11-19-1990

3.00 3.00a 4.00 OS/2

Summary: Bound COBOL programs can determine whether they are running in real or protected mode by calling the OS/2 API function DosGetMachineMode. The sample program below illustrates how this is done. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS OS/2, and to Microsoft COBOL Professional Development System (PDS) version 4.00 for MS OS/2.

More Information: Bound applications may need to know whether they are running in real (DOS) mode, or OS/2 protected mode. This can be determined by calling the OS/2 API function DosGetMachineMode. This function takes a single one-byte parameter and sets bit 0 if the program is running in protected mode, clearing it if in real mode. For more information on calling OS/2 API functions from COBOL 3.00 and 3.00a, see the file “OS2API.DOC” included with version 3.00a of the product. For more information on creating bound COBOL applications, see pages 4-11 to 4-12 of “Microsoft COBOL Compiler 3.0: Operating Guide” for versions 3.00 and 3.00a. For more information on the OS/2 API function DosGetMachineMode, see page 526 of “Advanced OS/2 Programming” by Ray Duncan (Microsoft Press, 1989). The following sample program (MACHMODE.CBL) illustrates how to call DosGetMachineMode. To compile, link, and bind the COBOL 3.00/3.00a program, enter the following commands from the OS/2 command prompt: pcobol machmode; link /nop machmode,,,pcobol doscalls; bind machmode cblbind.lib doscalls.lib -n @cblbind.not For COBOL 4.00, use the following compiling, linking, and binding commands: cobol machmode; link machmode,,,/nod lcobol os2; bind machmode cblbind.lib os2.lib -n @cblbind.not

MACHMODE.CBL
$SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. MachMode. DATA DIVISION. WORKING-STORAGE SECTION. * Clear all bits so it will easy to check status of bit 0. 01 MachineMode  PIC 9(2) COMP-5 VALUE 0. PROCEDURE DIVISION. CALL &quot;__DosGetMachineMode&quot; USING BY REFERENCE MachineMode. *   Check if bit 0 was set (2^0 = 1). IF MachineMode = 1 THEN DISPLAY &quot;This program is running in protected mode.&quot; ELSE DISPLAY &quot;This program is running in real mode.&quot; END-IF. STOP RUN. Copyright Microsoft Corporation 1990.