SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Dec 2007
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Accessing Custom C# .DLL Methods

    There are a lot of posts about accessing .NET base classes with the DotNetFactory object and using antiquated methods of accessing custom .dll's, but there is not a post that has sufficiently addressed the question of specifically using the DotNetFactory object to acccess the methods of a custom(not base class) .dll.

    Here is an Example custom C# .dll source that has one method to display a message box. -
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.ComponentModel;
    using System.Drawing;


    namespace QTPClassLibrary
    {
    public class HelloWorld
    {
    public HelloWorld()
    {

    }

    public void SayHelloWorld()
    {
    MessageBox.Show("Hello World!");
    }
    }
    }

    The DotNetFactory object syntax is -
    Set var_CreateInstance = DotNetFactory.CreateInstance (TypeName [,Assembly] [,args])

    The way to acccess base classes is simple -
    Set var_CreateInstance = DotNetFactory.CreateInstance("System.Windows.Forms .Form", "System.Windows.Forms")

    Somehow this gets difficult when you try to access your own .dll that is not in the GAC. you should be able to pass the constructor the full path to your .dll. It would look something like this, but it doesn't work -

    Set myVar = DotNetFactory.CreateInstance("QTPClassLibrary","Z: \Mercury Tools\QTP\GlobalCache\QTPClassLibrary.dll")
    myVar.SayHelloWorld
    Call wait(5)
    myVar.Dispose
    Set myVar = Nothing


    Has anyone gotten this to work with a custom .DLL? I don't want to use EXTERN or CreateObject. I want to use DotNetFactory.

    Thanks!
    Chif

  2. #2
    Junior Member
    Join Date
    Dec 2007
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Accessing Custom C# .DLL Methods

    Interestingly, I just got this to work after adding the assembly to the GAC. I don't really want to do this, because GAC is limited space, and I am concerned about protability, but some of you may want to do this.

    To add an assembly to the GAC, use the VisualStudio Command Line(not normal command line) -
    gacutil.exe /i "<full path to assembly>"

    Then the following code worked.

    Set myVar = DotNetFactory.CreateInstance("QTPClassLibrary.Hell oWorld", "QTPClassLibrary")
    myVar.SayHelloWorld
    Call wait(5)
    Set myVar = Nothing

  3. #3
    Junior Member
    Join Date
    Dec 2007
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Accessing Custom C# .DLL Methods

    Got it working without the GAC. As I suspected, I just had my syntax wrong. Here's what the QTP help ouhgt to say:

    Set myVar = DotNetFactory.CreateInstance("<namespace>.&l t;class>", "<full path to dll including dll filename")

    So in my case it was:

    Set myVar = DotNetFactory.CreateInstance("QTPClassLibrary.Hell oWorld", "c:\whatever\whatever.dll")

    and voila. Much easier than EXTERN stuff!

  4. #4
    Member
    Join Date
    Jan 2007
    Posts
    34
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Accessing Custom C# .DLL Methods

    hi ChifDagrif,

    thanks for the post - very helpful!

    I have a question on how you built the DLL. Was it using .NET framework 2.0? and did you use Visual Studio 2005?

    thanks!

  5. #5
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Accessing Custom C# .DLL Methods

    Does that matter at all for this DLL source code? I guess No

  6. #6
    Junior Member
    Join Date
    May 2006
    Location
    Mumbai
    Posts
    20
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Accessing Custom C# .DLL Methods

    Thread Hijack! Please use your old post to get a resolution for your issue.

  7. #7
    Member
    Join Date
    Jan 2007
    Posts
    34
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Accessing Custom C# .DLL Methods

    I dont see how this is a thread hijack?

    IF the DLL is built incorrectly the script will not work. Hence, getting the dll correctly build would be the first step.

    It would be great if someone could document:
    1. How to create a .NET DLL (so that it can be used in QTP)
    2. Creating a QTP sample project that demonstrates how to call the a function in the dll.

  8. #8
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Accessing Custom C# .DLL Methods

    [ QUOTE ]

    I dont see how this is a thread hijack?


    [/ QUOTE ]

    That was not for you.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 04:10 PM.

Copyright BetaSoft Inc.