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

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

问题描述

我正在尝试从QTP调用C#dll(使用vbscript)。我尝试了一些没有成功的东西:




  • Visual Studio 2010

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



代码:

 code> using System; 
使用System.Collections.Generic;
使用System.Text;

命名空间st
{
public class Class1
{
public static int GetValue()
{
return 34;
}
}
}




  • regasm / codebase st.dll


    • 失败,因为它不是一个有效的.NET程序集




在QTP / vbscript中,我尝试过




  • extern.Declare micInteger,GetValue,e:\st.dll,GetValue


    • 返回消息:'无效的过程调用或参数'




    • 不管QTP如何,我将非常感谢任何关于如何从.vbs文件调用c#dll的洞察。

      解决方案

      我可以通过执行以下操作来获得这个工作:



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

       命名空间st4 
      {
      public class st4_functions
      {
      public int GetValue()
      {
      return 34;
      }
      }
      }

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

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

      感谢所有回复我的问题。虽然我没有做COM解决方案,但是让我想到我可以继续使用.NET,并引导了这个解决方案。好的工作!



      编辑:



      我创建了一个博文步骤并提供其他信息:



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


      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.dll)

      code:

      using System;
      using System.Collections.Generic;
      using System.Text;   
      
      namespace st
      {
          public class Class1
          {
              public static int GetValue()
              {
                  return 34;
              }
          }
      }
      

      • regasm /codebase st.dll
        • fails 'because it is not a valid .NET assembly'

      In QTP/vbscript, I have tried

      • extern.Declare micInteger, "GetValue", "e:\st.dll", "GetValue"
        • Returns message: 'Invalid procedure call or argument'

      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:

      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

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

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