Microsoft KB Archive/65289

How to Hide Files with a Protected Mode COBOL Program

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

3.00 3.00a 4.00 OS/2

Summary: A protected mode COBOL version 3.00, 3.00a, or 4.00 program can hide files and directories by calling the OS/2 API function DosSetFileMode. The sample program below illustrates how to do 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 (PDS) version 4.00 for MS OS/2.

More Information: COBOL versions 3.00, 3.00a, and 4.00 can directly call OS/2 API functions by prefixing their names with a double underscore (__) and linking with the DOSCALLS.LIB library. DosSetFileMode takes the following parameters:

To make a file hidden, bit 1 of the second attribute parameter must be set. Note that in COBOL a WORD has a picture clause of 9(4) COMP-5, a DWORD has a picture clause of 9(8) COMP-5, and an ASCIIZ is a PIC X data item terminated with a null (ASCII 0). Data items prefixed with PTR must be passed BY REFERENCE; otherwise, they are passed BY VALUE. Furthermore, the parameters must be mentioned in reverse order in the CALL statement because COBOL’s calling convention is the reverse of OS/2’s. 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 DosSetFileMode, see page 561 of “Advanced OS/2 Programming” by Ray Duncan (Microsoft Press, 1989). The following sample program (HIDEFILE.CBL) allows you to hide or unhide files and directories. To compile and link the program in COBOL 3.00/3.00a, enter the following at the OS/2 command prompt: pcobol hidefile; link /nop hidefile,,,pcobol doscalls; The compiling and linking lines for COBOL Professional Development System (PDS) version 4.00 are as follows: cobol hidefile; link hidefile,,,coblib os2;

HIDEFILE.CBL
$SET ANS85 OSVS IDENTIFICATION DIVISION. PROGRAM-ID. HideFile. DATA DIVISION. WORKING-STORAGE SECTION. *  Pathname of the file. 01 FilePath   PIC X(256). *  New attribute of file. 01 Attribute  PIC 9(4) COMP-5. *  Reserved by OS/2, must be set to 0. 01 Reserved   PIC 9(8) COMP-5 VALUE 0. *  Operation desired by user (hide or unhide). 01 Operation  PIC 99   COMP-5. PROCEDURE DIVISION. *   Get a file name from the user and terminate it with a null. DISPLAY &quot;Enter name of file:&quot;. ACCEPT FilePath. INSPECT FilePath REPLACING FIRST &quot; &quot; BY X&quot;00&quot;. *   Loop until a valid operation is chosen. PERFORM UNTIL (Operation = 1) OR (Operation = 2) DISPLAY &quot;Hide (1) or UnHide (2)?&quot; ACCEPT Operation *      If operation to hide was chosen, set bit 1 of Attribute. EVALUATE Operation WHEN 1 MOVE 2 TO Attribute WHEN 2 MOVE 0 TO Attribute WHEN OTHER DISPLAY &quot;ERROR - Invalid operation&quot; CALL X&quot;E5&quot; END-EVALUATE END-PERFORM. *   Make the API call. CALL &quot;__DosSetFileMode&quot; USING BY VALUE    Reserved, BY VALUE    Attribute, BY REFERENCE FilePath. *   Check if an error occurred. IF RETURN-CODE NOT = 0 THEN DISPLAY &quot;ERROR - File not found&quot; CALL X&quot;E5&quot; ELSE DISPLAY &quot;Done.&quot; END-IF. STOP RUN. Copyright Microsoft Corporation 1990.