How to Use a NET DLL in QuickTest Professional

QTP/UFT Published on:
Code Hacker

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.



24 responses to “How to Use a NET DLL in QuickTest Professional”

    • 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

  1. 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?


  2. […] 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 […]

  3. 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?


    • 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

  4. 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)


  5. 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)

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

  7. 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

  8. 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 :)


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Code Hacker