ContentsIndexPreviousNext

M.2.5 Calling DLLs

You may call subroutines located in dynamic link libraries (DLLs) to access native code routines without relinking the runtime system.

To use a routine located in a DLL, you must first load, or CALL, the DLL. For example, to load the dynamic link library "MYLIB.DLL", you would CALL either "MYLIB.DLL" or simply "MYLIB". The runtime automatically appends ".DLL" when searching for a DLL. The runtime searches for DLLs after it has searched for COBOL programs.

The CALL statement that loads a DLL simply makes the routines contained in the DLL available to the COBOL program. The one exception to this is if the DLL contains a routine whose name is the same as the DLL. In this case, the routine is immediately called. For example, if the DLL "MYLIB.DLL" contained a routine called "MYLIB", then

CALL "MYLIB"

would both load the DLL and execute the MYLIB routine. To load the library and avoid calling the subroutine of the same name, specify ".DLL" explicitly in the CALL statement, as shown below:

CALL "MYLIB.DLL"

Once the library has been loaded, all of the routines it contains can be called. Loaded DLLs are searched immediately prior to searching for COBOL programs on disk. Routines contained in a DLL are called using either the direct C interface or the Pascal interface. As a result, you may pass parameters BY VALUE if that is required by the routine.

When you CANCEL a DLL, you may no longer call its component libraries. This action does release a small amount of memory.


Note: The CANCEL-ALL-DLLS configuration variable can be used to control whether or not CANCEL ALL will free DLLs. See Book 4, Appendix H for more details.
Routines called by this method are assumed to use either C or Pascal parameter passing conventions. The routine does not need to be written in the individual language, but must use its calling conventions. Virtually all of the library functions contained in the Windows Software Development Kit (SDK) are stored in DLLs and must be called using Pascal calling conventions. The DLL-CONVENTION configuration variable controls which interface the system uses. See Book 4, Appendix H for more details. If you attempt to call a routine that uses a different calling convention, the results are undefined (and usually fatal).