Microsoft KB Archive/37027

From BetaArchive Wiki

In OS/2 Protected Mode, COBOL 3.00 Can CALL .DLL But Not .EXE

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

3.00 3.00a OS/2

Summary: A COBOL Version 3.00 or 3.00a program cannot dynamically CALL to a separate .EXE program in OS/2 protected mode. To CALL a separate executable program in OS/2 protected mode, a COBOL Version 3.00 or 3.00a program must CALL a dynamic link library (DLL), not an .EXE program. The “Microsoft COBOL Compiler Version 3.0: Operating Guide” describes how to create a DLL on Pages 4-10 using ADIS and IXSIO as examples.

More Information: A related article, which describes how you must CHAIN to a .DLL and not to a .EXE program in MS OS/2 protected mode, can be found by querying on the following words: CHAIN and DLL and ADIS and IXSIO The following is an example of the steps required to create and CALL a DLL. 1. The following is a sample calling program, CALLING.CBL: PROCEDURE DIVISION. DISPLAY “IN THE MAIN PROGRAM”. CALL “CALLED”. DISPLAY “BACK IN THE MAIN PROGRAM”. STOP RUN. 2. The following is an sample called program, CALLED.CBL: PROCEDURE DIVISION. DISPLAY “IN THE CALLED PROGRAM”. DISPLAY “ABOUT TO RETURN TO THE MAIN PROGRAM”. EXIT PROGRAM. 3. Compile CALLING.CBL and CALLED.CBL with the following command lines: PCOBOL CALLING.CBL,,,ANS85; PCOBOL CALLED.CBL,,,ANS85; 4. To create a DLL out of the called subprogram, you must perform the following steps before linking: a. Create a DEF file for the called 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 called program, CALLED.DEF: LIBRARY INITINSTANCE ; CALLED 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 CALLED @1 ; assumes the PROGRAM-ID is CALLED. b. Set the LIBPATH environment variable in your CONFIG.SYS to tell OS/2 where to find the DLL files (for example, SET LIBPATH=C:). 5. The last step is to create two separate executables, CALLED.EXE and CALLING.EXE. The required link line for each object module is below. The /NOP and /NOD options 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. CALLED.OBJ must also be linked with the CALLED.DEF file that was created in the previous step. The object module is as follows: LINK CALLING /NOP /NOD,,,PCOBOL+DOSCALLS; LINK CALLED /NOP /NOD,,,PCOBOL+DOSCALLS, CALLED.DEF;

Copyright Microsoft Corporation 1990.