What is a DLL?
Dynamic Linked Library is MS implementation of shared library concept in Windows. To understand this term more clearly, DLL can be broken down into Dynamic Link(ed) + Library
- Dynamic Link means that the subroutines of a library are loaded into an application program at runtime, rather than being linked in at compile time, and remain as separate files on disk.
- Library is a collection of subroutines
How to know about the functions in a DLL?
It is assumed that if you intend to call a DLL, you should know the function to be called from inside and what that function does. If you are clueless about how to get the function names you can get download Microsoft Dependency Walker or a 3rd party utility called PE Explorer which can help you to find the functions.
How can the functions inside DLL be called from QTP?
This part is actually simple and a two step process…
- Declare the method using Extern.Declare
Example
Extern.Declare micHwnd, “FindWindow”, “user32.dll”, “FindWindowA”, micString, micString
where:
- micHwnd -the data type of value returned by method
- FindWindow -the user supplied procedure name. You can set it to anything as long as it’s a valid syntax.
- user32.dll -the DLL from where you wish to call the method
- FindWindowA -The actual method name inside the DLL
- Last two are the data types of the arguments that will be passed to the procedure
- Call the method
Example:
- Extern.FindWindow(“Notepad”, vbNullString)
To show the above process in action, here is an example to change the title of the Notepad window by calling the user32.dll
'Declare FindWindow method Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString 'Declare SetWindowText method Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString 'Get HWND of the Notepad window hwnd = Extern.FindWindow("Notepad", vbNullString) If hwnd = 0 then MsgBox "Notepad window not found" End if 'Change the title of the notepad window res = Extern.SetWindowText(hwnd, "LearnQTP.com")
Simple copy-paste the code above in your QTP ‘Expert View’. Open a blank notepad window. Run this code. You will now see that the name has changed from Untitled-Notepad to LearnQTP.com
References:Wiki DLL
If you want to keep track of further articles on UFT (QTP). I recommend you to subscribe by email below and have new UFT articles sent directly to your inbox.
Tomek says
Hi Ankur,
pls tell me, in same way we declare external functions/variables from .vbs file? could you give an short example how we it should be done? Thanks in advance Tomek
Irfan says
This article is very good.. self explanatory!
Shiva says
Whatever info provided above is informative…thanx alot
MY exact Questions is…if i have written the set of functions in one library
Now, if I have any chance to save this as a DLL file and place in where QTP has its dump of DLL’s. now will I able to call all the methods in that library as part of intellisence????
Thanks
Shiva
Ankur Jain says
@shiva: QTP doesn’t support intellisense at that level yet.
shiva says
Hi ankur,
is it possible to write the userdefined methods to DLL’s
and call them into VBScript as part of intellisence???
if so, pls guide me with appropriate steps
Thanks.
Ankur Jain says
@shiva: Could you please ask your question on the QTP forums.
Shirkaan says
Hi…
thanks for such a usefull code…
i have created one dll in C++ using visual studio 2005.
Can i use it into QTP while scripting in VB???
How to link my dll to dcript????
Prasanna says
Hi Ankur,
The above article very usefull.
I have questions
1. Is the Dot Net frame work library(Dlls) can be imported? and Is General Functions can be used for our application to automate?
Rao says
May I know how to call Java APIs in QTP?
New Bee says
HI,
could you please explain us, how dlls benifits a qtp script.
mastanbabu says
hello ankur i have doubt how to test a treeview through QTP
Fidel says
Ive had no problems installing v.9.2 on Vista!
Rav says
Hey Luiz,
Lemme know if its Vista 😉 Am sure it it 🙂
ravinder.pal.singh80@gmail.com
Anonymous says
Hey Luiz,
Lemme know if its Vista 😉
I could help you with that 🙂
sufware.hunk@yahoo.com
Luiz says
Good Text Guy. Sometimes we need to use already created functions. Very Useful.
Man, I have another questions. I’m facing some problems to install my qtp since some days. Could you inform me your e-mail to discuss a little about it?
My e-mail is vendrame2@hotmail.com.
Many Thanks man.