在 vbscript 中调用 C# dll [英] Calling C# dll in vbscript

查看:48
本文介绍了在 vbscript 中调用 C# dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 QTP 调用 C# dll(使用 vbscript).我尝试了很多方法都没有成功:

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
  • 创建 C# 类库 (st.dll)

代码:

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

namespace st
{
    public class Class1
    {
        public static int GetValue()
        {
            return 34;
        }
    }
}

  • regasm/codebase st.dll
    • 失败,因为它不是有效的 .NET 程序集"
    • 在 QTP/vbscript 中,我尝试过

      In QTP/vbscript, I have tried

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

        无论 QTP,我将不胜感激任何有关如何从 .vbs 文件调用 c# dll 的见解.

        Regardless of QTP, I would greatly appreciate any insight on how to call the c# dll from a .vbs file.

        推荐答案

        我能够通过执行以下操作来使其正常工作:

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

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

        Create a new C# dll in VS 2010.

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

        在 QTP 中,我添加了以下几行:

        In QTP I added the following lines:

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

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

        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!

        我创建了一篇博文来详细说明步骤并提供其他信息:

        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

        这篇关于在 vbscript 中调用 C# dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆