You want to use the functions of a user-created library in WinCC. In this entry we show how a sample DLL is incorporated in WinCC. At the moment, DLLs created in Visual Basic cannot be incorporated in WinCC at Runtime with VBS
.More information on the use of DLLs is available in the WinCC Information System under: "Working with WinCC > ANSI-C for creating functions and actions > Using DLLs in functions and actions".
| No. |
Procedure |
| 1 |
Sample DLL: Use a C compiler to
create the library "T1_C.dll" from the following program code.
You can download the ready-compiled DLL here.
T1_C.zip ( 17 KB )
extern "C" __declspec (dllexport) int aufruf1 (int a);
#include <stdio.h>
#include <windows.h>
FILE *h_test;
FILE *h_trace;
extern "C" __declspec (dllexport) int aufruf1(int a)
{
h_test= fopen
("C:/temp/test_dll.txt","a");
if (h_test)
{
fprintf(h_test, "Function 'aufruf1' was called!\n");
fclose
(h_test );
}
a+=100;
return a;
};
N.B.
- The DLL must be created without debug information.
- All the DLL functions used in WinCC must be specified in the
corresponding syntax at the beginning of the DLL (see the first
line in the sample DLL "T1_C.dll").
- In order to be able to use the DLL functions, they must be
incorporated in the action or function in WinCC at the beginning
with the "#pragma code" instruction.
|
| 2 |
Incorporate the "T1_C.dll" library in WinCC with C script
and execute the "aufruf1" function: The following WinCC
tags were used:
- var1 (signed 32-bit value)
- result (signed 32-bit value)
Create the following C script on the "mouse-click" event of a
button:
#include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char*
lpszPropertyName)
{
#pragma code ("c:/temp/T1_C.dll")
int aufruf1(int a);
#pragma code ()
int value;
value = GetTagDouble("var1"); //Return-Type:
double
SetTagDouble("result",aufruf1(value));
//Return-Type: BOOL
}
|
| 3 |
Result:
![点击在新窗口查看原始图片 wincc调用自定义dll库]()
Fig. 01
|