QTP-How to Use a NET DLL in QuickTest Professional/Functional Testing

Automation Guild Online Conference Top ad

Sometimes you need functionality that QTP does not provide. Other times you may need to interact with an existing DLL. Using a simple C# DLL, that we create, I will show how you can easily call it in QuickTest Pro.

Creating a Simple .NET DLL

Open Visual Studio (If you don't have a copy of Visual Studio you can download a free copy of Visual C# Express.) and create a new ‘Class Library' project named QTP.UI.Automation:

Rename Class1 to QTP:

Next let's add a simple function that take two numbers and adds them together:

Go to the QTP.UI.Automation properties and make sure you have the following:

Make sure the ‘Make assembly COM-Visible' is checked.

Go to the Build section and make sure that the ‘Register for COM interop' is checked:

Build your solution (F6) and make sure there are no errors.

Call Your DLL in QuickTest Pro

Start QTP and add the following code:

Set oTestCom = CreateObject(“QTP.UI.Automation.QTP”)

msgbox oTestCom.Add(6,4)

QTP should return 10

Cool – that's it.

Malay - September 14, 2011

May appear as a very basic question.
What is the relation between COM and DLL?

    Joe Colantonio - September 17, 2011

    Hi Malay – the way I understand it is the DLL contains your functions and COM (Component Object Model) enables QTP to be able to communicate with the DLL. Cool~Joe

ElizaF - September 16, 2011

Thank you for this – opens up all sorts of new possibilities for work and play for me.

    Joe Colantonio - September 17, 2011

    ElizaF » Awesome – have fun! Cheers~Joe

Anish Pillai - September 17, 2011

Hi Joe,

Good informative article.. :) :)

I have the following queries regarding this topic –

1. Where is this DLL saved. If I want to execute the same logic in some other machine, the how do I copy the DLL?
2. Can you specify any real scenarios where using this approach will be helpful?


Service Test 11 – How to create a C# function library — Joe Colantonio -- Test Automation Geek | Bibliomaniac | Software Imagineer - September 17, 2011

[…] 1. Create a simple .NET DLL. For this example I will use a .NET DLL that I created that contains an Add function. The Add function takes two numbers and adds them together. For a step by step example on how to create this function check out my blog post QTP – How to Use a .NET DLL in QuickTest Professional/Functional Testing […]

Uday - October 5, 2011

Hi Joe,

How QTP knows that, the method exists in that dll file?

I know, you included the reference i.e “QTP.UI.Automation”, does it mean while building the solution it saves the solution reference some where and when i refere this in QTP, it looks in that location?


    Joe Colantonio - October 7, 2011

    Uday » When you build the DLL in Visual Studio I believe that it automatically enters all the Method info in the registry. If you wanted to use the DLL on another machine you need to use RegAsm.exe to register it. Does that make sense? Thanks for the question! Cheers~Joe

KG - October 13, 2011

Hi Joe,

Thanks for providing this interesting stuff. Can you please share the information of how Intellisense works for the custom dll.

In the above example you provided, after creating the object oTestCom, Intellisense should prompt with the available functions (in this case “Add” function)


KG - October 17, 2011

Thanks Joe. Also I found an interesting article on Intellisense using .NET


udhayakumar - February 8, 2012

Hi Joe,

i Added developers dll in reference to subcribe event . Finally i created the dll to use in qtp. But it doesnt give the triggered event state. what would be the problem?

Dim oEventObject
Dim pjstate1,cjstate1

Function subscribepj(pjstates)
msgbox pjstates
End Function
Function subscribecj(cjstates)
msgbox cjstates
End Function
Set pjstate1 = GetRef(“subscribepj”)
Set cjstate1 = GetRef(“subscribecj”)
Set oEventObject = DotNetFactory.CreateInstance(“JobManager.Listener”,”C:\Documents and Settings\uarumuga\My Documents\visual studio 2010\projects\JobManager\JobManager\bin\Debug\JobManager.dll”)

msgbox oEventObject.getcjstate(cjstate1)
msgbox oEventObject.getpjstate(pjstate1)

lagunascorpio - May 30, 2012

Nice one. This helped me a lot. Those COM checkboxes did the trick for me. Couldn’t find that tip anywhere else.

    Joe Colantonio - May 31, 2012

    lagunascorpio » Great! Glad to hear it worked for you.

leon - December 5, 2012

if I want use the dll in the other pc, how can i do?

    Joe Colantonio - December 6, 2012

    leon » Hi Leon – you should be able to copy the dll over to another machine that has .net installed. Make sure to place it in the same folder location

adrian Acosta - March 6, 2013

Hi Joe, one question:
i can use description.create in visual basic .net?


Mark - April 17, 2013

Is there a VB DLL example? instead of C#

Mahesh Upadhyay - November 21, 2013

Hi Joe,

Nice Post.

I have a query here, if i try to access database using Register for COM intercop i am finding error “Object doesn’t support this property or method: ‘oTestCom.connect’ “.

Please do let me know what exactly i did wrong

NT - July 30, 2014

Hey Joe,
this is an interesting easy to understand article. Please keep up the good work.. definitely helps beginners like me.

I have a doubt here. I want to create a C# GUI with a grid that will capture test object and action to be taken on that object.

If i have to execute the same action using QTP, is there any straight forward mechanism that i can leverage to construct the Action Step string that QTP understands and executes
Kindly suggest

If not then i guess its a tough way out coding in a series of function calls.

Thanks in advance :)


    Joe Colantonio - August 2, 2014

    Cool – glad it helped. I’m not sure if this can be done — has anyone else tried. If so can you please share with us. Cheers~Joe

[BLOCKED BY STBV] QTP and .Net dll - July 31, 2014

[…] did this forum become a sales platform for Tarun? QTP-How to Use a NET DLL in QuickTest Professional/Functional Testing | Joe Colantonio – Selenium-UF… Here's a link to a very clear example of using a C# dll in […]

Click here to add a comment

Leave a comment: