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

查看:982
本文介绍了在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#类libary(st.dll)

代码:

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

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




  • regasm /基本代码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:

        创建于2010年VS新的C#DLL

        Create a new C# dll in VS 2010.

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

        在QTP添加以下行:

        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天全站免登陆