Microsoft KB Archive/36399

In OS/2 Protected Mode, COBOL 3.00 Must CHAIN to .DLL Not .EXE

PSS ID Number: Q36399 Article last modified on 03-09-1990

3.00 3.00a OS/2

Summary: A COBOL program cannot CHAIN to an .EXE program in OS/2 protected mode. In OS/2 protected mode, a COBOL program must CHAIN to a dynamic link library (DLL), not to an .EXE program. Page 4-10 of the “Microsoft COBOL Compiler 3.0: Operating Guide” describes how to create a DLL using ADIS and IXSIO as examples.

More Information: A related article, which describes how you must dynamically CALL to a .DLL and not to a .EXE program in MS OS/2 protected mode, can be found by querying on the following words: CALL and DLL and ADIS and IXSIO The following is an in-depth example of the steps required to create and CHAIN to a DLL: 1. The following is a sample chaining program, CHAINING.CBL: PROCEDURE DIVISION. DISPLAY “IN THE MAIN PROGRAM”. CHAIN “CHAINED”. STOP RUN. 2. The following is a sample chained program, CHAINED.CBL: PROCEDURE DIVISION. DISPLAY “IN THE CHAINED PROGRAM”. EXIT PROGRAM. 3. Compile CHAINING.CBL and CHAINED.CBL with the following command lines: PCOBOL CHAINING.CBL,,,ANS85; PCOBOL CHAINED.CBL,,,ANS85; 4. To create a DLL out of the CHAINed subprogram, you must perform the following steps before linking: a. Create a .DEF file for the CHAINed program. The .DEF file allows the linker to place information in the .EXE header describing the attributes of the executable that the OS/2 loader needs at load time. For instance, the LIBRARY statement is used to tell the loader that the executable is a dynamic link library. The following is the .DEF file for the CHAINed program, CHAINED.DEF: LIBRARY INITINSTANCE ; CHAINED is a DLL. PROTMODE ; needs to run in protected mode. DATA NONSHARED ; expects OS/2 to duplicate data areas ; for each task. CODE LOADONCALL ; load when needed. EXPORTS CHAINED @1 ; assumes that the PROGRAM-ID is CHAINED. b. Set the LIBPATH environment variable in your CONFIG.OS2 to tell OS/2 where to find the DLL files (for example, SET LIBPATH=C:). You must reboot after the CONFIG.OS2 file has been altered. 5. The last step is to create two separate executables, CHAINED.EXE and CHAINING.EXE. The required link line for each object module is shown below. The NOP and NOD switches tell the linker not to pack the code segments and not to use the default libraries, respectively. All OS/2 programs must be linked with the PCOBOL and DOSCALLS libraries so that the linker creates an OS/2 application instead of a DOS Version 3.x application. CHAINED.OBJ must also be linked with the CHAINED.DEF file that was created in the previous step. The program is as follows: LINK CHAINING /NOP /NOD,,,PCOBOL+DOSCALLS; LINK CHAINED /NOP /NOD,,,PCOBOL+DOSCALLS, CHAINED.DEF;

Copyright Microsoft Corporation 1990.