Are there any examples of extending 4Test functionality through DLL calling?
SilkTest provides the functionality to call C functions declared in windows DLLs (dynamic link libraries). The functions are declared in 4Test and then called from the scripts. Primarily advanced users use this feature, as do automation developers who wish to call their own C functions. However, DLL calling can be used in a very simple fashion to quickly extend SilkTest functionality for all users.
An example of enhancing SilkTest via DLL calls is the addition of mathematical functions. Since SilkTest provides functionality for so many testing issues, you may be surprised to learn that SilkTest does not include built-in functions for common mathematical functions like calculating the sine or cosine of an angle. However, these functions are built into the Windows operating system and easily accessed by SilkTest.
In this example, the functions needed are provided in the Windows DLL "msvcrt40.dll". This DLL is part of the Microsoft Visual C Runtime library. This DLL contains functions for sine, cosine, and tangent, as well as many others. If help is required in determining which functions exist in Windows DLLs, a Windows developer should be able to help (as can anyone with Windows programming tools installed on their computer).
To declare the functions that you wish to use in SilkTest, put the following declarations at the top of the file:
[-] dll "msvcrt40.dll" [ ] DOUBLE cos (DOUBLE dAngle) [ ] DOUBLE sin (DOUBLE dAngle) [ ] DOUBLE tan (DOUBLE dAngle)
SilkTest locates files in the computer"s system directory without needing path information, so only the filename needs to be referenced.
In the above declarations, note that each function returns a value of type DOUBLE. Each function also takes an input data value, also of type DOUBLE, for the angle. SilkTest supports C data types, such as DOUBLE, for use in calling DLL functions. The DOUBLE data type corresponds to the REAL data type in SilkTest. Variables of type REAL can be declared to contain the data needed for the above functions:
REAL rAngle // angle in radians REAL rCos // cosine of the angle
The Cosine function can then be called as follows:
rCos = cos (rAngle)
Note that the input angle to this function is specified in radians. If you are working with angles in degrees, write a function to convert them to radians by multiplying by Pi and dividing by 180.