Example of Calling C functions from COBOL

The following example shows how C functions can be accessed from a COBOL program:

$set rtncode-size"4"
 working-storage section.
 01 str.
     03 str-text    pic x(10).
     03 filler      pic x  value x"00". 
* Null terminate string for C function
 01 counter  pic 9(8) comp-5  value zero.

 procedure division.
 call-c section.
     call "cfunc" using str, counter
     if return-code not = zero
* RETURN-CODE set from return () in C

         display "ERROR"
     else
         display "OK"
     end-if
     stop run.
------------------------------------------------

The following applies to Windows only:

__declspec(dllexport)
int func(char* st, int *c)
{
   ...
   return(0);
}