Calling C# dll in vbscript

前端 未结 3 433
日久生厌
日久生厌 2020-12-30 15:22

I am trying to call a C# dll from QTP (uses vbscript). I have tried a number of things with no success:

  • Visual Studio 2010
  • Create C# class libary (st
相关标签:
3条回答
  • 2020-12-30 15:26

    Your function is static. Static class members can't be matched up to interface members, and if it can't implement a .NET interface then it certainly won't implement a COM interface.

    0 讨论(0)
  • 2020-12-30 15:37

    I was able to get this working by doing the following:

    Create a new C# dll in VS 2010.

    namespace st4
    {
        public class st4_functions
        {
            public int GetValue()
            {
                return 34;
            }
        }
    }
    

    In QTP I added the following lines:

    Set obj = DotNetFactory.CreateInstance("st4.st4_functions", "c:\\st4.dll")
    MsgBox obj.GetValue()
    

    Thanks to all that responded to my problem. Though I did not do the COM solution, it got me thinking that I could stay with .NET and led to this solution. Good job all!

    EDIT:

    I created a blog post to detail the steps and provide additional information:

    http://www.solutionmaniacs.com/blog/2012/5/29/qtp-calling-c-dll-in-vbscript.html

    0 讨论(0)
  • 2020-12-30 15:39

    As Marc said, but I think it merits an answer. If you ensure that your dll will be available though the COM mechanics, your script should be able to call into it with things like CreateObject.

    How to register .NET assembly for COM interop

    0 讨论(0)
提交回复
热议问题