04 February 2010

Using external Dynamic Link Library (DLL) File with Quick Test Professional using Extern

We can use an external DLL with QTP which is not otherwise included with the windows system or not available in vbscript. For using an external DLL with QTP you need to use EXTERN. Using EXTERN we can access any DLL file at any location within the hard drive of your system by specifying the file path.

Syntax -
Extern.Declare(RetType, MethodName, LibName, Alias [, ArgType(s)])


Dim xmlPath
xmlPath = "C:\PROGRA~1\"
Print xmlPath
'Retrieving the long path name from the short path name using an external DLL file 'kernel32.dll
Dim val, retValue, myExtern
Set myExtern = CreateObject("Mercury.ExternObj")
'Create an object of Mercury.ExternObj

myExtern.Declare micString,"GetLongPathName", "kernel32.dll",
"GetLongPathNameA",micString,micString + micByRef ,micDword
'Making a call to the DLL file kernel32.dll and accessing its GetLongPathNameA 'function and declaring the supported parameters

val = myExtern.GetLongPathName(xmlPath,retValue,256)
'retValue contains the actual longpath
Print retValue


In order to understand as to which parameters will be there for each Extern statement for a specific DLL, you need to access the DLL  reference document. If you are trying to call any of the Microsoft Windows DLL files. You can find a complete reference on the MSDN Library - 
For the one i have used in the example, you can visit -


  1. Thank you for this, it helped me quite a bit.