Microsoft KB Archive/65104

OS/2 COBOL Program to Get Machine Configuration; DosDevConfig

PSS ID Number: Q65104 Article last modified on 11-21-1990

3.00 3.00a 4.00 OS/2

Summary: A protected mode COBOL program can call the OS/2 API function DosDevConfig to find out machine-configuration information, such as how many printers are attached, how many serial ports and floppy disk drives are available, whether or not a math coprocessor is present, and the type of primary display adapter (monochrome or color). Below is a sample program demonstrating this. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS OS/2, and to Microsoft COBOL Professional Development System version 4.00 for MS OS/2.

More Information: DosDevConfig takes the following parameters:

Microsoft COBOL versions 3.00, 3.00a, and 4.00 can directly call OS/2 API functions by prefixing the name of the function with a double-underscore (__) and linking with the DOSCALLS.LIB library. Note that a BYTE in COBOL has a picture clause of 9(2) COMP-5, and a WORD has a picture clause of 9(4) COMP-5. Also, data items preceded by PTR must be passed using the BY REFERENCE clause in the CALL statement; otherwise, BY VALUE is used. Furthermore, the parameters must be passed to the API function in the reverse order because the API functions use a calling convention that is the reverse of COBOL’s. For more information on calling OS/2 API functions from COBOL 3.00 and 3.00a, see part 9 of the “Release Notes” section of the “Microsoft COBOL Compiler 3.0: Operating Guide.” For more information on DosDevConfig, see pages 509-510 of “Advanced OS/2 Programming” by Ray Duncan (Microsoft Press, 1989). The following sample program (MACHINFO.CBL) displays configuration information about the machine, namely, how many printers are attached, how many serial ports and floppy disk drives are available, whether or not a math coprocessor is present, and the type of primary display adapter (monochrome or color). Note that a printer does not have to be online to be “attached.” To compile and link the program in COBOL 3.00/3.00a, enter the following at the OS/2 command prompt: pcobol machinfo; link /nop machinfo,,,pcobol doscalls; The compile and link lines for COBOL PDS 4.00 are as follows: cobol machinfo; link machinfo,,,coblib os2;

MACHINFO.CBL
$SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. MachInfo. DATA DIVISION. WORKING-STORAGE SECTION. *  Receives machine information. 01 Info        PIC 9(2) COMP-5. *  Initialize to find out number of printers attached. 01 InfoNeeded  PIC 9(4) COMP-5 VALUE 0. *  Reserved by OS/2, must be set to 0. 01 Reserved    PIC 9(4) COMP-5 VALUE 0. PROCEDURE DIVISION. *   Get number of printers attached. CALL &quot;__DosDevConfig&quot; USING BY VALUE    Reserved, BY VALUE    InfoNeeded, BY REFERENCE Info. DISPLAY &quot;There are &quot; Info &quot; printers attached.&quot;. *   Get number of serial ports available. MOVE 1 TO InfoNeeded. CALL &quot;__DosDevConfig&quot; USING BY VALUE    Reserved, BY VALUE    InfoNeeded, BY REFERENCE Info. DISPLAY &quot;There are &quot; Info &quot; serial ports available.&quot;. *   Get number of floppy disk drives available. MOVE 2 TO InfoNeeded. CALL &quot;__DosDevConfig&quot; USING BY VALUE    Reserved, BY VALUE    InfoNeeded, BY REFERENCE Info. DISPLAY &quot;There are &quot; Info &quot; disk drives available.&quot;. *   Check if math coprocessor is available. MOVE 3 TO InfoNeeded. CALL &quot;__DosDevConfig&quot; USING BY VALUE    Reserved, BY VALUE    InfoNeeded, BY REFERENCE Info. IF Info = 1 THEN DISPLAY &quot;A math coprocessor is present.&quot; ELSE DISPLAY &quot;A math coprocessor is not present.&quot; END-IF. *   Get the type of primary display adapter (color or mono). MOVE 6 TO InfoNeeded. CALL &quot;__DosDevConfig&quot; USING BY VALUE    Reserved, BY VALUE    InfoNeeded, BY REFERENCE Info. IF Info = 1 THEN DISPLAY &quot;The primary display adapter is color.&quot; ELSE DISPLAY &quot;The primary display adapter is monochrome.&quot; END-IF. STOP RUN. Copyright Microsoft Corporation 1990.