Cicode Programming Reference > Cicode Function Categories > DLL Functions Introduction > DLLOpen


Opens a link to a DLL function, by loading the specified DLL library into memory and attaching it to the named function. After you open the function link, you can call the function with the DLLCall() function. You pass the function number returned from the DLLOpen() function as an argument in the DLLCall() function.

One accepted method for interfacing with a DLL function is to write a Cicode function file. This file contains the DLLOpen() function to initialize the functions, and one Cicode function for each DLL function, as an interface. In this way, you can hide the DLL interface in this file. Any other Cicode function will call the Cicode interface, and the call to the DLL remains transparent.

Please be aware that DLLs need to be on the path. The file extension is not required.

Note: You need to specify the arguments to the function correctly. CitectSCADA has no way of checking the number and type of arguments to the function. If you specify the number of arguments incorrectly, your computer may display unexpected behavior. You should test your interface thoroughly before using it on a live system.



Ensure that you specify the arguments to the DLLOpen() function correctly according to the following list.

Failure to follow these instructions can result in death, serious injury, or equipment damage.


DLLOpen(sLib, sName, sArgs)


The DLL library name.


The function name. An underscore (_) is required in the function name for a 'C' function, but not for a Pascal function. When you call a DLL from a Cicode function, sName needs to be the same as the name defined in the .DEF file used to link the DLL. The file extension is not required.


The string specifying the function arguments. The first character in the string is the return value of the function.

A - Logical.

B - IEEE 8 byte floating point number.

C - Null terminated string. Maximum string length 255 characters.

D - Byte counted string. First byte contains the length of the string, maximum string length 255 characters.

H - Unsigned 2 byte integer.

I - Signed 2 byte integer.

J - Signed 4 byte integer.

Return Value

The DLL function handle, or -1 if the library or function could not be found or loaded.

Related Functions

DLLCall, DLLClose


/* This function is called when CitectSCADA starts up,
to initialize the DLLs that are called */
INT hAnsiUpper;
INT hGlobalAlloc;
! Open DLL to AnsiUpper
hAnsiUpper = DLLOpen("USER.DLL", "AnsiUpper", "CC");
hGlobalAlloc = DLLOpen("Kernel", "GlobalAlloc", "IIJ");
/* This is the Cicode entry point into the DLL function call. This function hides the DLL interface from the rest of CitectSCADA. */
FUNCTION AnsiUpper(STRING sString)
STRING sResult;
sResult = DLLCall(hAnsiUpper, "^"" + sString + "^"");
RETURN sResult;
/* Allocate memory and return memory handle */
FUNCTION GlobalAlloc(INT Mode, INT Length)
STRING sResult;
INT hMem;
sResult = DLLCall(hGlobalAlloc, Mode : #### + "," + Length : ####);
hMem = StrToInt(sResult);

See Also

DLL Functions