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
1: 'Declare FindWindow method
2: Extern.Declare micHwnd, “FindWindow”, “user32.dll”, “FindWindowA”, micString, micString
3:’Declare SetWindowText method
5: Extern.Declare micLong, “SetWindowText”, “user32.dll”, “SetWindowTextA”, micHwnd, micString
7: ‘Get HWND of the Notepad window
8: hwnd = Extern.FindWindow(“Notepad”, vbNullString)
10: if hwnd = 0 then
12: MsgBox “Notepad window not found”
14: end if
16: ‘Change the title of the notepad window
17: 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
- QTP Documentation
Have you downloaded the FREE Optimizing QTP eBook yet? Get It Now!
If you want to keep track of further articles on QTP. I recommend you to subscribe via RSS feed. You can also subscribe by Email and have new QTP articles sent directly to your inbox.




8 comments ↓
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.
Hey Luiz,
Lemme know if its Vista
I could help you with that
sufware.hunk@yahoo.com
Hey Luiz,
Lemme know if its Vista
Am sure it it
ravinder.pal.singh80@gmail.com
Ive had no problems installing v.9.2 on Vista!
hello ankur i have doubt how to test a treeview through QTP
HI,
could you please explain us, how dlls benifits a qtp script.
May I know how to call Java APIs in QTP?
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?
Leave a Comment