Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Are there any examples of extending 4Test functionality through DLL calling?

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.
 

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:24
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.