Platform Invoke is a .NET technique that enables managed code to call unmanaged functions implemented in dynamic link libraries
(.dlls).
For more information on Platform Invoke see the Visual Studio Help topic
Consuming Unmanaged Code.
Platform invoke is similar to an API call. It enables managed COBOL to use the COBOL CALL statement to call native COBOL that
is built as a
.dll.
If you have existing COBOL that you want to call from managed code, you must first build it as a native
.dll with the entry points that you need to call. You then add the
.dll as a reference to your .NET project.
In your .NET project, you write a managed COBOL program and use CALL statements to call functions in the
.dll. These CALL statements generate a platform invoke call if the CALL matches an entry in the native
.dll.
To use Platform Invoke to call native COBOL
- Package your native COBOL as a
.dll with the necessary entry points into the code.
- Add the
.dll and the COBOL run-time system support to your COBOL project as references, as follows:
- Right-click
References in the solution view on the right.
- Click
Add reference.
- Browse to
MicroFocus.COBOL.Runtime and select it.
- On the Projects tab, browse to your
.dll and select it.
- Write some
.NET COBOL to call your
.dll, using the standard COBOL CALL statement, such as:
CALL myNativeLibrary USING myParams
- Now non-COBOL managed code can invoke the above managed COBOL, which in turn calls the native COBOL
.dll.