在 VBScript 中使用 DLL

编程入门 行业动态 更新时间:2024-10-27 16:28:19
本文介绍了在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 21:22:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/813759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:VBScript   DLL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!