Rational Developer for System z
COBOL for Windows, Version 7.5, Programming Guide


Dealing with a Windows restriction

In general, you cannot use SYSTEM(STDCALL) linkage for programs that are called by means of a procedure pointer or a function pointer if the calls have any arguments. This restriction is due to the associated convention for forming names (known as name decoration).

With STDCALL linkage, the name is formed by appending to the entry name the number of bytes in the parameter list. For example, a program named abc that passes an argument by reference and a 4-byte integer by value has 8 bytes in the parameter list; the resulting name is _abc@8. You cannot set a procedure pointer or a function pointer to the address of an entry point because there is no syntactical way to specify the arguments that are to be passed to the entry point in the SET statement; the generated name will have '0' as the number of bytes in the parameter list. The link fails because of unresolved external references when the entry point has arguments.

Use the CALLINT compiler directive to ensure that calls using a procedure pointer or a function pointer to programs with arguments use the OPTLINK convention. For example:

CBL
   IDENTIFICATION DIVISION.
   PROGRAM-ID. XC.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01   PP1 PROCEDURE-POINTER.
   01   HW  PIC X(12).
   PROCEDURE DIVISION USING XA.
* Use OPTLINK linkage:
      >>CALLINT OPTLINK
      SET PP1 TO ENTRY “X”.
* Restore default linkage:
      >>CALLINT
      MOVE “Hello World.” to HW
      DISPLAY “Calling X.”
* Use OPTLINK linkage:
      >>CALLINT OPTLINK
      CALL PP1 USING HW.
* Restore default linkage:
      >>CALLINT
      GOBACK.
   END PROGRAM XC.

* Use OPTLINK linkage:
   CBL ENTRYINT(OPTLINK)
   IDENTIFICATION DIVISION.
   PROGRAM-ID. X.
   DATA DIVISION.
   LINKAGE SECTION.
   01   XA    PIC 9(9).
   PROCEDURE DIVISION USING XA.
      DISPLAY XA.
      GOBACK.
   END PROGRAM X.

Without using the CALLINT compiler directives and the CALLINT compiler option, you would have an unresolved reference to _X@0 when you link.

If the called program is in C or PL/I and uses the STDCALL interface, use the pragma statement in the called program to form the name without STDCALL name decoration.

related references
Compiler-directing statements
Call interface conventions


Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)