Microsoft KB Archive/38665

From BetaArchive Wiki

Mixing Calls of Statically and Dynamically Linked Programs

PSS ID Number: Q38665 Article last modified on 04-20-1993

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

The information in this article applies to:
- Microsoft COBOL for MS-DOS and OS/2, versions 3.0 and 3.0a


Question: How do I statically link some of my routines together and yet dynamically call executable routines at run time from the same COBOL Version 3.0 program?

Response: Place a double underscore (__) before the routines that you want to declare as public symbols in the linked executable. The other calls will search for executable files to load into memory at the time of the call. When calling assembly-language routines from COBOL Version 3.0, the assembly routine must be statically linked to the COBOL program. To do this, you must create public symbols for the calls to the assembly routines. The LITLINK directive will create public symbols for all CALLed routines. Appending a double underscore to the program name in the CALL statement will cause the compiler to create a public symbol for that routine. This method will allow you to mix static and dynamic calls. Separately compile the two COBOL Version 3.0 programs shown further below (FIRST.COB and THIRD.COB) into object modules. Assemble the Microsoft Macro Assembler Version 5.1 program shown below (SECOND.ASM) into an object module. Then LINK the object modules (.OBJ files) as follows: LINK FIRST+SECOND; LINK THIRD; The FIRST.OBJ COBOL routine is statically linked with the assembler routine (SECOND.OBJ). The THIRD.OBJ COBOL routine is linked into a separate .EXE program. At run time, the first COBOL routine calls the statically linked assembler routine and also dynamically calls the separate THIRD.EXE COBOL routine. FIRST.COB is as follows: ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 PASS-VAR1 PIC 9(4) USAGE COMP-0 VALUE 0. 01 PASS-VAR2 PIC 9(4) USAGE COMP-0 VALUE 0. 01 PASS-VAR3 PIC 9(4) USAGE COMP-0 VALUE 0. 01 TEMP-VAR PIC XX. PROCEDURE DIVISION. 0000-MAIN. DISPLAY “Checking the printer status…” AT 0310 WITH BLANK SCREEN. CALL "__prntstat" USING PASS-VAR1, PASS-VAR2, PASS-VAR3. DISPLAY “The printer status is:” AT 0510 PASS-VAR1. DISPLAY “AND THE DUMMIES:” AT 0710 PASS-VAR2 " " PASS-VAR3. CALL “THIRD”. ACCEPT TEMP-VAR. STOP RUN. SECOND.ASM is as follows: .MODEL large .CODE public prntstat ;make routine visible to COBOL prntstat proc far ;declare it as a far call push bp ;save value of bp mov bp,sp ;load bp with top of stack mov si,[bp+14] ;get address of 3rd parameter mov byte ptr [si+1],55 ;change value to 55 mov si,[bp+10] ;get address of 2nd parameter mov byte ptr [si+1], 99 ;change value to 99 mov si,[bp+6] ;get address of 1st parameter mov ah,02h ;function 2 - get printer status mov dx,0 int 17h ;make function call mov byte ptr [si+1],ah ;status is placed in low byte of ;1st parameter mov byte ptr [si],0 ;zero out high byte of parameter pop bp ;restore bp ret 12 ;restore stack prntstat endp end THIRD.COB is as follows: PROCEDURE DIVISION. DISPLAY “HELLO FROM COBOL SUBPROGRAM”. EXIT PROGRAM.

Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.