Rapise provides APIs for calling managed (.NET) and UnMnaged(x86) dynamic
link libraries (DLLs) from test scripts.
Managed
(.NET) DLLs
There are 3 methods defined for object g_util to access the managed DLL:
inst = g_util.CreateClassInstance(
dllPath, className )
Parameters
- dllPath:
path to the DLL containing the class.
- className:
name of class.
Return Value: class instance.
g_util.SetFieldValue( obj,
fieldName, value )
Parameters
- obj:
object that owns the field.
- fieldName:
name of the field.
- value:
value to set
fieldValue = g_util.GetFieldValue(
obj, fieldName )
Parameters
- obj:
object that owns the field.
- fieldName:
name of the field.
Return Valuefield value.
g_util.InvokeMember(dllPath,
className, methodName, obj, methodParams )
Parameters
- dllPath:
path to the DLL containing the class.
- className:
name of the class containing specified method.
- methodName:
name of the method to evaluate.
- obj:
an instance of object.
- methodParams:
parameters of the method.
Return Valueresult of the method call.
Sample
var calc =
g_util.CreateClassInstance(("TestLibrary\\TestLibrary\\bin\\Release\\TestLibrary.dll", "TestLibrary.Calculator");
g_util.InvokeMember(
"TestLibrary\\TestLibrary\\bin\\Release\\TestLibrary.dll",
"TestLibrary.Calculator",
"GetName",
null,
[ ]
);
var strictMode =
g_util.GetFieldValue(calc, "strictMode");
UnManaged
(x86) DLLs
Treatment of x86 (native) DLLs is done via "DynaWrapper" helper
object. This object links to functions exported from DLL by means of
"Register" method.
For example, calling MessageBox may be done as follows:
var UserWrap = WScript.CreateObject("DynamicWrapper");
// Call MessageBoxA(), first
register the API function
// i=describes the number and data
type of the functions parameters
//
// f=type of call _stdcall or
_cdecl. So it can work with both MS C++ and
// Borland C++. Default to
_stdcall. If that doesn't work use _cdecl. If
// that doesn't work good luck!
//
// r=return data type.
//
// a IDispatch*
// c signed char
// d 8 byte real
// f 4 byte real
// k IUnknown*
// h HANDLE
// l long
// p pointer
// s string
// t short
// u unsigned int
// w wide string
UserWrap.Register("USER32.DLL", "MessageBoxA", "I=HsSu", "f=s", "R=l");
// now call the function
UserWrap.MessageBoxA( null, "MessageBox
(ANSI)", "From DynaWrap Object",
3);