Work with C functions
This topic contains tips for using C code functions with your TruClient 2.0 - Web scripts.
Using C functions
C functions are defined in the C-functions.c file. During replay, they can be called from an Evaluate C step.
You drag and drop an Evaluate C step from the Steps box Miscellaneous tab, and set the Function Name value to the name of the C function to call.
For details, see Steps box Miscellaneous tab.
Define C functions
The C-functions.c file includes an empty main function, void main().
You can add your own C code to the default main function. For example, by calling the following function, “hello” is logged.
void main() {
lr_message("hello");
}
You can also define your own functions, for example:
void logHello() {
lr_message("hello");
}
Call functions defined in DLL or shared object
You can call C functions defined in DLL (Windows) or a shared object (Linux). This is done using the lr_load_dll(library name) API.
In the following example, the function loads the user32.dll and calls MessageBoxA defined in it. This API displays a message box in Universal Windows Platform.
void showMessageBox()
{
lr_load_dll("user32.dll");
MessageBoxA(NULL, "Hello world!", "message", 0);
}
void main()
{
showMessageBox();
}
For details, see lr_load_dll.
See also: