Calling COBOL From Other Windows Programs

To simplify the process of calling an ACUCOBOL-GT program from other programming languages in a Windows environment, the ACUCOBOL-GT 32-bit Windows runtime is encapsulated in a DLL file. This DLL file has been further encapsulated in a COM server.

To call ACUCOBOL-GT from other Windows programs, you can do one of two things:

  1. Create an object for the ACUCOBOL-GT COM server in the source program and call the methods of that object. This is covered in the topic Using the ACUCOBOL-GT COM server.
  2. Call the ACUCOBOL-GT runtime DLL in the source program. This call requires special declarations, and is explained in Calling the Runtime DLL.

The advantage of using the COM server is that you can treat the ACUCOBOL-GT system as a COM object. You do not need to insert declarations into the source code of the other programming language, you can operate in a multi-threaded environment, and the development environment is more intuitive. Using the ACUCOBOL-GT runtime DLL instead of the COM server can provide slightly improved performance and makes application distribution smaller and installation easier. However, the DLL can be called only from a single thread of execution. For example, if you call a COBOL program from a user interface control's event procedure, and the event procedure is called again before the COBOL program returns, you must detect this case and either wait or inform the user of the error.

Regardless of which approach you choose, when a program written in another language calls an ACUCOBOL-GT program, the data is passed as a pointer to a variant type for each parameter. The ACUCOBOL-GT program receives a handle for each parameter and uses a library routine to convert the data to COBOL types. When ACUCOBOL-GT data items are passed back to this program, they pass through another library routine that converts the data back into variant types. The C$GETVARIANT and C$SETVARIANT library routines are detailed in Library Routines.

The parameters of the COM server methods, or exported DLL functions, are all null-terminated strings, integers, or variant type variables. In some programming languages, such as Visual Basic (VB), the variant type is used by default for any variables that have not been assigned a data type. Because the variant type is used to represent many different types of data, you generally don't have to convert these types of data when they are assigned to a variant variable. The programming language automatically performs any necessary conversion. Because the ACUCOBOL-GT COM server and runtime DLL routines take variant type parameters, it is easy to receive variables from, or return variables to, other languages.

Note: All the examples in this section use Visual Basic as the source language for code samples. Microsoft conventions for object description language are used for the descriptions of method usage.