0

How to add a custom DLL into QTP , Actually I need certain methods to be used in vbscript (QTP) present in a DLL file , now how to refer to that particular DLL in QTP is it possible

Can anyone help me out since m new to QTP

Ganeshja
  • 2,675
  • 12
  • 36
  • 57

2 Answers2

1

You can use extern.Declare to declare an external function that resides in a dll. Use Extern.{name of function} to use that function.

Example to see if the cursor is displayed as an hour glass:

extern.Declare micLong,"GetForegroundWindow","user32.dll","GetForegroundWindow" 
extern.Declare micLong,"AttachThreadInput","user32.dll","AttachThreadInput",micLong,
micLong,micLong 
extern.Declare micLong,"GetWindowThreadProcessId","user32.dll",
"GetWindowThreadProcessId",micLong,micLong 
extern.Declare micLong,"GetCurrentThreadId","kernel32.dll","GetCurrentThreadId" 
extern.Declare micLong,"GetCursor","user32.dll","GetCursor" 

function get_cursor() 
    hwnd = extern.GetForegroundWindow() 
    pid = extern.GetWindowThreadProcessId(hWnd, NULL) 
    thread_id=extern.GetCurrentThreadId() 
    extern.AttachThreadInput pid,thread_id,True 
    get_cursor=extern.GetCursor() 
    extern.AttachThreadInput pid,thread_id,False 
end function 

Msgbox get_cursor() 

For more usages, you can always refer to the help function of QTP. It is actually quite good!

AutomatedChaos
  • 7,267
  • 2
  • 27
  • 47
  • Example above is for user32.dll but how to call any other custom dll say a .net dll containing a func Log? Can anybody elaborate? Where to keep the dll or load it in memory how to do it? – rahoolm Jan 08 '14 at 10:06
  • @rahoolm, I would suggest creating a new question for this. Did you register the .dll with regsrv32.exe? When you are using .net dll's, consider using the `dotnetfactory` object in QTP to interact with them. – AutomatedChaos Jan 08 '14 at 14:24
0

You can same implement in vbscript and associate this function library with your tests...