Calling DLLs in QTP

DLL--Dynamic Link Library
It has basically programs, these can be called from any application, by creating instance for the dll / reference to the DLL.

The DLLs can be developed in c,c++,java,.net...etc
Usually all the dlls related to Windows OS are available in  C:\WINDOWS\system32 folder and we can refer MSDN help to know the system DLLs and the functions available in these DLLs

User created dlls are also should be copied into this folder and should be registered before using.


To register usercreated dlls   regsvr32 can be used.


To call the methods or properties in the DLL


1. using DotnetFactory

''below is the syntax to refer DLL and call the methods

Dim myobj

Set myobj=DOTNetFactory.CreateInstance("namespace.class", "path of the dll")
myobj.method  ''to call the method
myobj.property '' to access the property


2. Using Extern Object


 ' The below script will check Notepadwindow is available or not
 'Here we are using user32.dll


 Extern.Declare micHwnd,"FindWindow","user32.dll","FindWindow", micString, micString
 hwnd = Extern.FindWindow("Notepad", vbNullString)
 if hwnd = 0 then
   MsgBox "Notepad window not found"
 else
   MsgBox "Notepad window found"
 end if
-----------------------------

Comments