- You must load the DLL to call it's function. (Even if it is already loaded by the system, you must implement it.) There are
three ways to load a DLL in ACUCOBOL-GT: you can CALL it, use the "-y" runtime option, or use the SHARED_LIBRARY_LIST configuration
variable. These are described fully in the section
Calling DLLs from COBOL of this chapter.
- If you CALL a DLL, you can enter any of the following:
CALL "MyDll"
CALL "MyDll.dll"
CALL "C:\MyDir\MyDll.dll"
We recommend the middle option. The last won't work if your system is mobile. If you set CODE_PREFIX, the runtime looks for
the DLL in the CODE_PREFIX directory. If it is not found, it also tries the Windows system directory.
- You must indicate the DLL calling convention in your COBOL program. The vast majority of the time, the convention for Windows
API DLLs is WINAPI also known as stdcall. You can specify calling conventions in ACUCOBOL-GT in several ways:
- You must indicate "A" or "W", ANSI/wide, in the function name if both ANSI and Unicode versions of the function are available.
See
Microsoft Documentation for a more detailed description.
- You must adhere to case sensitivity of the function name.
- You must terminate any strings that you pass to a function. Use x"00" (LOW-VALUES) as in the following examples:
STRING "My example" LOW-VALUES DELIMITED BY SIZE INTO target-string.
or
INSPECT target-string REPLACING TRAILING SPACES BY x"00".
- Do not use literals with Windows functions.
- You must map your ACUCOBOL-GT handle to the Windows handle. For example:
INQUIRE acuhandle SYSTEM HANDLE IN syshandle
Then "syshandle" can be passed on to the Windows API function. You declare the handle in Working-Storage like this:
77 syshandle usage pointer.
- You should cancel the DLL when finished using it. For example:
CANCEL "mydll.dll".
Note that DLLs loaded with "-y" or SHARED_LIBRARY_LIST cannot be cancelled or unloaded.
- Always pass string variables BY REFERENCE. In C, BY REFERENCE is indicated by an "&". You can also use BY REFERENCE when the
data type is prefixed with LP, as in LPSTR.
You can pass a numeric value BY REFERENCE or BY VALUE, depending on how the function is implemented. See
Microsoft Documentation for more information.
CALL a function BY CONTENT to make a copy of it and provide an address to the copy. This lets users read, not modify, content.
- Most Windows API functions return only "true" or "false" when they succeed or fail. You must call GetLastError for specific
reasons.
- Whatever memory you allocate via ACUCOBOL-GT's M$ALLOC routine, it is your responsibility to release/free via M$FREE.