在 VBScript 中使用 DLL [英] Using DLLs in VBScript

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

问题描述

我已将 C# 代码编译成 DLL,但对它们的经验很少.我的 C# 代码包含一个带有静态方法 Print() 的类 HelloWorld.我想在 VBScript 中使用这个 DLL 来调用方法 Print().我知道这是基础,但我将其用作对最终将被编译为 DLL 的更大规模项目的测试.声明看起来像什么,方法调用看起来如何?

I've compiled C# code into a DLL, but have little experience with them. My C# code contains a class HelloWorld with a static method Print(). I'd like to use this DLL in VBScript to call the method Print(). I know this is base, but I'm using this as a test for a larger scale project that will be compiled to DLL in the end. What's the declare look like for that and how would the method call look?

推荐答案

重要:只有当 DLL 公开 COM 接口时,这两种方法才有效.

Important: Both methods will work only if the DLL exposes a COM interface.

如果您的 dll 已在系统中注册,请使用带有 ProgID 的 CreateObject.

If your dll is registered with the system, use CreateObject with it's ProgID.

Set myObject = CreateObject("MyReallyCoolObject.HelloWorld")
myObject.Print

如果您的对象未在系统上注册,请使用带有包含您的对象的文件的路径的 GetObject.确保您的对象公开了正确的接口.(第二个参数是可选的.如果你的对象公开了多个,你可以在这里提供一个类名.)

If your object is not registered on the system, use GetObject with a path to the file containing your object. Make sure your object exposes the proper interface. (The second parameter is optional. Here you can provide a class name if your object exposes more than one.)

Set myObject = GetObject("C:somepathhelloworld.dll", "appname.HelloWorld")
myObject.Print

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

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