在vbscript中调用C#dll

Edw*_*eno 6 c# dll vbscript qtp

我试图从QTP调用C#dll(使用vbscript).我尝试了很多没有成功的事情:

  • Visual Studio 2010
  • 创建C#类libary(st.dll)

码:

using System;
using System.Collections.Generic;
using System.Text;   

namespace st
{
    public class Class1
    {
        public static int GetValue()
        {
            return 34;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)
  • regasm /codebase st.dll
    • 失败'因为它不是有效的.NET程序集'

在QTP/vbscript中,我试过了

  • extern.Declare micInteger, "GetValue", "e:\st.dll", "GetValue"
    • 返回消息:'无效的过程调用或参数'

无论QTP如何,我都非常感谢有关如何从.vbs文件调用c#dll的任何见解.

Edw*_*eno 8

通过执行以下操作,我能够实现此目的:

在VS 2010中创建一个新的C#dll.

namespace st4
{
    public class st4_functions
    {
        public int GetValue()
        {
            return 34;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在QTP中我添加了以下行:

Set obj = DotNetFactory.CreateInstance("st4.st4_functions", "c:\\st4.dll")
MsgBox obj.GetValue()
Run Code Online (Sandbox Code Playgroud)

感谢所有回应我的问题.虽然我没有做COM解决方案,但它让我觉得我可以继续使用.NET并导致这个解决方案.干得好!

编辑:

我创建了一篇博文,详细介绍了这些步骤并提供了更多信息:

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