Load Method

Applies to TestComplete 15.20, last modified on January 19, 2022

Description

The IDLLAccessProcess.Load method loads a particular dynamic link library in TestComplete and returns a pointer to the library. Later, this pointer can be used to call routines from the DLL. Before you load a DLL, you should define its type and type of its functions using the IDLLAccessProcess.DefineDLL method and methods of the IDefineDLL object. IDLLAccessProcess.Load "binds" these definitions with the actual library code. If the specified DLL is not found, IDLLAccessProcess.Load displays an error message.

Declaration

IDLLAccessProcessObj.Load(LibraryName, LibraryType)

IDLLAccessProcessObj An expression, variable or parameter that specifies a reference to an IDLLAccessProcess object
LibraryName [in]    Required    String    
LibraryType [in]    Optional    String Default value: Empty string   
Result Pointer to the library

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

LibraryName

The file name, extension and absolute or relative path to the dynamic link library. If the file extension is omitted, Load uses .dll. If the path is not specified, the method searches for the DLL in the following order:

  1. The folder, in which TestComplete is installed.
  2. The current working folder of the TestComplete process.
  3. The <Windows>\System32 (or the <Windows>\System) folder.
  4. The <Windows> folder.
  5. The folders specified in the PATH variable.
The WOW64 subsystem may redirect calls to some system libraries when you work with 32-bit applications. To load a library of a particular bitness, specify the full path to the required library.

LibraryType

The name of the DLL type defined by IDLLAccessProcess.DefineDLL. If it is omitted, TestComplete uses the DLL file name as the DLL type name (the file extension is excluded). For example, if you call the following code, TestComplete will use User32 as the DLL type name.

JavaScript, JScript

DefEnv = DLL.DefineEnvironment();
...
Lib = DefEnv.Load("C:\\Windows\\System32\\User32.DLL");

Python

DefEnv = DLL.DefineEnvironment()
# ...
Lib = DefEnv.Load("C:\\Windows\\System32\\User32.DLL")

VBScript

Set DefEnv = DLL.DefineEnvironment()
...
Set Lib = DefEnv.Load("C:\Windows\System32\User32.DLL")

DelphiScript

DefEnv := DLL.DefineEnvironment();
...
Lib := DefEnv.Load('C:\Windows\System32\User32.DLL');

C++Script, C#Script

DefEnv = DLL["DefineEnvironment"]();
...
Lib = DefEnv["Load"]("C:\\Windows\\System32\\User32.DLL");

Result Value

A pointer to the specified dynamic link library.

Example

The code below defines the DLL type and loads the DLL of the specified type from script. Then, the routine defines a procedure from the specified library and calls this procedure from the test.

JavaScript, JScript

function DefineProcDemo()
{
  // Defines the DLL type
  var DefDLL = DLL.DefineDLL("user32");
  // Loads the DLL in memory
  var Lib = DLL.Load("C:\\Windows\\System32\\user32.dll");
  // Defines the procedure
  DefDLL.DefineProc("GetWindowTextA", VT_UI4, VT_LPSTR, VT_I4, VT_I4);
  // ...

  // Creates an alias for the procedure
  DefDLL.DefineAlias("GetWindowText", "GetWindowTextA");
  // ...

  var hndl = Sys.Process("Notepad").Window("Notepad").Handle;
  var winText = DLL.New("LPSTR", 256);
  // Calls the routine using the alias
  Lib.GetWindowText(hndl, winText, 20);
  Log.Message(winText)
}

Python

def DefineProcDemo():
  # Defines the DLL type
  DefDLL = DLL.DefineDLL("user32")
  # Loads the DLL in memory
  Lib = DLL.Load("C:\\Windows\\System32\\user32.dll")
  # Defines the procedure
  DefDLL.DefineProc("GetWindowTextA", VT_UI4, VT_LPSTR, VT_I4, VT_I4)
  # ...
  # Creates an alias for the procedure
  DefDLL.DefineAlias("GetWindowText", "GetWindowTextA")
  # ...
  hndl = Sys.Process("Notepad").Window("Notepad").Handle
  winText = DLL.New("LPSTR", 256)
  # Calls the routine using the alias
  Lib.GetWindowText(hndl, winText, 20)
  Log.Message(winText)

VBScript

Sub DefineProcDemo
  ' Defines the DLL type
  Set DefDLL = DLL.DefineDLL("user32")
  ' Loads the DLL in memory
  Set Lib = DLL.Load("C:\Windows\System32\user32.dll")
  ' Defines the procedure
  Call DefDLL.DefineProc("GetWindowTextA", VT_UI4, VT_LPSTR, VT_I4, VT_I4)
  ' ...

  ' Creates an alias for the procedure
  Call DefDLL.DefineAlias("GetWindowText", "GetWindowTextA")
  ' ...

  hndl = Sys.Process("Notepad").Window("Notepad").Handle
  Set winText = DLL.New("LPSTR", 256)
  ' Calls the routine using the alias
  Call Lib.GetWindowText(hndl, winText, 20)
  Call Log.Message(winText)
End Sub

DelphiScript

procedure DefineProcDemo;
var DefDLL, Lib, hndl, winText;
begin

  // Defines the DLL type
  DefDLL := DLL.DefineDLL('user32');
  // Loads the DLL in memory
  Lib := DLL.Load('C:\Windows\System32\user32.dll');
  // Defines the procedure
  DefDLL.DefineProc('GetWindowTextA', VT_UI4, VT_LPSTR, VT_I4, VT_I4);
  // ...

  // Creates an alias for the procedure
  DefDLL.DefineAlias('GetWindowText', 'GetWindowTextA');
  // ...

  hndl := Sys.Process('Notepad').Window('Notepad').Handle;
  winText := DLL.New('LPSTR', 256);
  // Calls the routine using the alias
  Lib.GetWindowText(hndl, winText, 20);
  Log.Message(winText);
end;

C++Script, C#Script

function DefineProcDemo()
{
  // Defines the DLL type
  var DefDLL = DLL["DefineDLL"]("user32");
  // Loads the DLL in memory
  var Lib = DLL["Load"]("C:\\Windows\\System32\\user32.dll");
  // Defines the procedure
  DefDLL["DefineProc"]("GetWindowTextA", VT_UI4, VT_LPSTR, VT_I4, VT_I4);
  // ...

  // Creates an alias for the procedure
  DefDLL["DefineAlias"]( "GetWindowText", "GetWindowTextA" );
  // ...

  var hndl = Sys["Process"]("Notepad")["Window"]("Notepad")["Handle"];
  var winText = DLL["New"]("LPSTR", 256);
  // Calls the routine using the alias
  Lib["GetWindowText"](hndl, winText, 20);
  Log["Message"](winText)
}

See Also

Specifics of Using 32- and 64-bit DLLs
Calling DLL Functions From Tests - Tutorial
IDefineDLL Object

Highlight search results