The following example shows a COBOL program that calls a C/C++ dynamic link library (DLL) by using the CALL statement.
The example illustrates the following concepts:
Do the following steps to create and run the example:
#include <windows.h>
#include <string.h>
#include <stdio.h>
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD,LPVOID);
_declspec (dllexport) int Sub(void);
BOOL WINAPI DllMain (
HANDLE hModule,
DWORD dwFunction,
LPVOID lpNot)
{
return TRUE;
}
_declspec (dllexport) int Sub(void)
{
printf (“Hello from sub.\n”);
return 0;
} LIBRARY Sub
EXPORTS
Subcl /EHsc /LD /DLL /DEF:sub.def sub.ccbl CALLINT(CDECL),PGMNAME(MIXED),LIST
Identification Division.
Program-Id. “Driver”.
Data Division.
Working-Storage Section.
77 rc pic 9(8) usage binary.
Procedure Division.
Display “Hello World, from Driver”
Call “Sub” returning rc
Display “Sub Returned to Driver”
Goback.cob2 -g -v driver.cbl -IMP:sub.librelated tasks
Building dynamic link libraries
related references
cob2 options
CDECL
CALL statement
(COBOL for Windows Language Reference)