Microsoft KB Archive/62262

Call DosQCurDisk to Get Current Drive in OS/2 Protected Mode

PSS ID Number: Q62262 Article last modified on 06-14-1990

3.00 3.00a OS/2

Summary: Microsoft COBOL versions 3.00 and 3.00a protected mode programs can call the DosQCurDisk OS/2 API function to get the current drive. These versions of COBOL can call API functions directly, prefixing their names with a double underscore; for example: CALL &quot;__DosQCurDisk&quot; USING BY REFERENCE DriveBitmap, BY REFERENCE DriveCode. For more information on calling OS/2 API functions from COBOL 3.00 and 3.00a, see the file OS2API.DOC included with 3.00a. For more information on DosQCurDisk, see Page 547 of “Advanced OS/2 Programming” by Ray Duncan (Microsoft Press, 1989). This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS OS/2.

More Information: DosQCurDisk requires that the following data items be passed to it: PTR WORD Receives current drive code (1 = A, 2 = B, etc.). PTR DWORD Receives logical drive bitmap (logical drives A-Z correspond to bits 0-25; a bit is set if a logical drive exists). The second parameter is not important in getting the current drive, but it is worthy to note that for API functions, a DWORD (4 bytes) has a picture clause of “9(8) COMP-5”. Likewise, a WORD (2 bytes) has a picture clause of “9(4) COMP-5”. Since the specification requires pointers to these data items, they must be passed using the BY REFERENCE clause. Remember also that API functions use a calling convention that is the reverse of COBOL’s, so the parameters must be passed in the reverse order. The sample program below (GETDRIVE.CBL) reports the current drive. To compile and link the program, use the following: pcobol getdrive; link /nop getdrive,,,pcobol doscalls;

Code Example
DATA DIVISION. WORKING-STORAGE SECTION. * Receives the current drive code (A = 1, B = 2, etc.). 01 DriveCode     PIC 9(4) COMP-5. * Used to display letter corresponding to DriveCode. 01 DriveLetter   REDEFINES DriveCode PIC XX. * Receives bitmap of logical drives' availability. 01 DriveBitmap   PIC 9(8) COMP-5. PROCEDURE DIVISION. *   Call the API function to get the current drive. CALL &quot;__DosQCurDisk&quot; USING BY REFERENCE DriveBitmap, BY REFERENCE DriveCode. *   Drive letter A = drive code 1 but A has ASCII 65. COMPUTE DriveCode = DriveCode + 64. DISPLAY &quot;The current drive is &quot; AT 2501. DISPLAY DriveLetter(1:1) AT 2522. STOP RUN. Copyright Microsoft Corporation 1990.