background image
<< Calling DLL Passing arguments to DLL functions | Using PVCS with SilkTest >>
Calling DLL Passing arguments to DLL functions
<< Calling DLL Passing arguments to DLL functions | Using PVCS with SilkTest >>
User's Guide
429
24 C
ALLING
W
INDOWS
DLL
S
F
ROM
4T
EST
S
CRIPTS
Passing arguments to DLL functions
// 4Test declaration
type REC is record
...
STRING sName, size=32
...
To pass a
NULL
pointer to a
STRING
, use the
NULL
keyword in 4Test. If a
DLL sets an out parameter of type char* to a value larger than 256 bytes, you
need to initialize it in your 4Test script before you pass it to the DLL
function. This will guarantee that the DLL does not corrupt memory when it
writes to the parameter. For example, to initialize an out parameter named
my_parameter, include the following line of 4Test code before you pass my_
parameter to a DLL:
my_parameter = space(1000)
Pointers
When passing pointers to C functions, use these conventions:
·
Pass a 4Test string variable to a DLL that requires a pointer to a character
(null terminated).
·
Pass a 4Test array or list of the appropriate type to a DLL that requires a
pointer to a numerical array.
·
Pass a 4Test record to a DLL that requires a pointer to a record. 4Test
records are always passed by reference to a DLL.
Note You cannot pass a pointer to a function to a DLL function.
Arguments that can be
modified by the DLL
function
An argument whose value will be modified by a DLL function needs to be
declared using the out keyword. If an argument is sometimes modified and
sometimes not modified, then declare the argument as in and then, in the
actual call to the DLL, preface the argument with the out keyword, enclosed
in brackets. For example, the third argument (lParam) to the SendMessage
DLL function can be either in or out. Therefore, it is declared as follows:
// the lParam argument is by default an in argument
dll "user.dll"
LRESULT SendMessage (HWND hWnd, UINT uiMsg, WPARAM
wParam, LPARAM lParam)
Then, to call the DLL with an out argument, you use the keyword out,
enclosed within brackets:
SendMessage (Open.hWnd, WM_GETTEXT, 256, [out] sText)
For more information, see "dll declaration" in online Help.
Window handles
If a parameter takes a window handle, use the hwnd property or the
GetHandle method of the AnyWin class to get the window handle you need.