从VBScript调用控制台应用程序中的函数 [英] Call a function in a console app from VBScript

查看:75
本文介绍了从VBScript调用控制台应用程序中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台应用程序myapp.exe。在应用程序中有一个函数,我们称它为:

I have a console app, myapp.exe. Within the app is a function, let's call it:

public static int AddIntegers(int a, int b)

是否可以使此函数在外部可见,以便VBscript可以调用它?我是否必须将函数移到DLL中,或者可以将其保留在EXE中并使其可见?如果是,怎么办?

Is it possible to make this function visible externally so that a VBscript could call it? Do I have to move the function into a DLL or can I leave it in the EXE and make it visible? If so, how?

推荐答案

理想地,您应该制作一个DLL并在需要公开的功能上设置Com Visible。

Idealistically, you should be making a DLL and set Com Visible on the functions you need to expose.

using System;
using System.Runtime.InteropServices;
namespace MyDLL
{
   [ComVisible(true)]
   public class Operations
   {
       [ComVisible(true)]
       public int AddIntegers(int a, int b)
       {
           return a + b;
       }
    }
}

编译后DLL,您需要在regasm.exe中进行注册,以便可以从VBScript调用它:

After you've compiled your DLL you need to register it with regasm.exe so that you can call it from VBScript:

Dim myObj
Set myObj = CreateObject("MyDLL.Operations")
Dim sum
sum = myObj.AddIntegers(3, 5)

此回复基于CodeProject发布的如何从VBScript调用.NET DLL ,作者是Raymund Macaalay。我建议您阅读它。

This reply is based on the CodeProject posting How to call a .NET DLL from a VBScript by Raymund Macaalay. I recommend you read it.

此外,您还应该检查其他stackoverflow发布信息,例如如何从VBScript调用C#DLL函数

Also, you should check other stackoverflow posting such as How to call C# DLL function from VBScript.

这篇关于从VBScript调用控制台应用程序中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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