Promotic
WikipediaLinkedInYoutubeTwitterFacebook

Examples of calling functions in Dll libraries

Description of ExamDLL example

The example is placed in the folder /Pm/Examples/Others/PmDll/Exam.

The example demonstrates usage of the DLL (dynamic linked libraries), their connection with the PROMOTIC system and calling the functions contained in these libraries.

The following objects were created in this example application:

The PmDll object named "Func" and graphic panel (PmPanel).

The "Func" object of the PmDll type used in order to access functions in DLL. On its page Dll it is necessary to set the full path to the file of the required library (in this case FuncDLL.dll).

The panel contains two buttons that call the designer's methods MaxDll and SumDll of panel.

 
The panel method SumDll calls the function Sum from library FuncDLL that sums two integers. The result is written into the Debug_info item in the INFO system.
 
The SumMax panel method works the same way with the only difference that when it is called, the Max function from the FuncDLL library is runned for finding the maximum from three integers. The result is also written into the Debug_info item.
Listing from script:
in the designer's method MaxDll of the "Main" panel:
VBScriptSelect and copy to clipboard

Dim p(2)
p = Array(CLng(3), CLng(5), CLng(2))
Pm.Debug "Max(3, 5, 2) = " & pMe.Pm("/Func").Fce.Max(p)
 
In this case passing a parameter to the function is a litte bit complicated as the Max function takes the structure consisting of three integers as a parameter. This structure is created in PROMOTIC as an array of the length 3. To pass it to the function correctly, each value of the array has to be converted by the CLng function to 4-bytes integers. The reason for this is that in VBScript each new variable is automatically assigned to corresponding data type. But this type needn't correspond to the type that is required by the library function which can be programmed in another language. Structured data types need to be passed by references. In this case the Max function is created so that it takes the structure of three numbers of the Integer type (it means that 3*4 bytes). That's why before calling Max, each number must be explicitly converted to 4-bytes value of the Long type. See Syntax description of the declaration file of the DLL library functions.
 
Description of FuncDLL.dll:

This library was created in the programming language C++. It offers two functions:

- Sum(a, b) function, whose parameters a, b are two integers passed by value and it returns their sum a+b.
- Max(st) function has st as an input parameter passed by reference that is a data structure consisting of three integer (4-bytes) values. Returns an integer that is their maximum.
 
The source code of the library in the language C++ is supplied with the example in the FuncDLL.cpp file. This file is not needed when calling functions from the PROMOTIC system.
 
To allow PROMOTIC to call functions included in the DLL library, the declaration file needs to be created. This file has to have the same name as the corresponding library but the extension .inc (in the case the name is FuncDLL.inc), and it must be located in the same folder as the library. Each its line contains the declaration of one function. It is not needed to declare all functions from the library but only those that are used in the PROMOTIC system. See Syntax description of the declaration file of the DLL library functions.
PROMOTIC 8.3.26 SCADA system documentation - MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice