DLL

(Engine-Level Function)

Description: Returns a value of a type specified by its parameter from a call to Microsoft Windows™ dynamic link library using the C calling convention.
Warning: For use by advanced users only. Great care must be taken that all parameter values are correct when using this statement, since incorrect usage may cause a system crash.
Returns: varies (see table under ReturnType)
Usage: Script Only.
Function Groups: DLL
Related to: LoadDLL
Format: DLL(DLLName, FuncName, ReturnType, BuffLen, Type1, Val1, Type2, Val2, …)
Parameters:  
DLLName   
Required. Any text expression that gives the full path, file name, and extension of the DLL to load, or the handle returned from a LoadDLL statement.
FuncName   
Required. Any text expression that gives the name of the function to call in the DLL.
ReturnType   
Required. The return type of the DLL function, as shown in the following table

ReturnType

Attribute

0

Void (return value only)

1

16 bit Integer

2

32 bit Integer

3

64 bit Double

4

Pointer to a buffer (*)

5

HWnd value of VTScada Object 

BuffLen   
Required. Any numeric expression that gives the length of the returned buffer, if ReturnType is 4.
Type1, Val1, Type2, Val2, …   
Required. Are any expressions that determine the type of parameter passed to the DLL function, as shown in the table for the ReturnType parameter. The corresponding ValN parameter will be cast as this type before it is passed to the DLL function.
Comments:

This statement allows a wide variety of other routines and code to be used in an application.

(*) If a DLL function takes a parameter of type 4 (buffer), then it should only read/write that buffer while the DLL's function is running - it should not store it for later. The pointer that gets passed into the DLL function points to a buffer that only exists for the lifetime of the DLL function call.

64-bit VTScada can load only 64-bit DLLs. 32-bit VTScada can load only 32-bit DLLs.

VTScada Internet Clients (VICs) can load only 32-bit DLLs regardless of whether the VTScada server is 32-bit or 64-bit.

Example:  

You have a DLL that has:

  • A function named decrypt(), which returns a length of the decrypted file.
  • A function named getDecryptedFile()

The DLL calls from VTScada script would look like so:

  DllHandle = LoadDLL("C:\Path\To\mydll.dll");
  If Valid(DllHandle) Done;
  [
    decryptedFileLength = DLL(dllHandle, "decrypt", 2, ...);
    decryptedFile = DLL(dllHandle, "getDecryptedFile",  4, decryptedFileLength, ...); 
  ]

An array of C# objects cannot be transferred directly via DLL(). Multiple files (as per the above example) could be passed in several ways. For example:

  • Your DLL's decrypt() function could be written to return the number of files. Then in a loop, another call is made to the DLL to determine the length of the n-th file and finally retrieve that file from the DLL
  • Serialize the array. For example, "<32 bit length of first decrypted file><contents of first file><32 bit length of second decrypted file>...", and then convert that into an array in VTScada via SRead().