简体   繁体   English

在VBScript中使用DLL

[英]Using DLLs in VBScript

I've compiled C# code into a DLL, but have little experience with them. 我已将C#代码编译成DLL,但对它们几乎没有经验。 My C# code contains a class HelloWorld with a static method Print() . 我的C#代码包含一个带有静态方法Print() HelloWorld类。 I'd like to use this DLL in VBScript to call the method Print() . 我想在VBScript中使用这个DLL来调用方法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. 我知道这是基础,但我正在使用它作为一个大规模项目的测试,最终将编译为DLL。 What's the declare look like for that and how would the method call look? 声明的内容是什么样的,方法调用看起来如何?

If your dll is registered with the system, use CreateObject with it's ProgID. 如果您的dll已在系统中注册,请使用带有ProgID的CreateObject

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

If your object is not registered on the system, use GetObject with a path to the file containing your object. 如果您的对象未在系统上注册,请使用GetObject以及包含对象的文件的路径。 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:\some\path\helloworld.dll", "appname.HelloWorld")
myObject.Print

I think you might be looking for Registration-Free COM . 我想你可能正在寻找免注册COM This SO answer regarding the Microsoft.Windows.ActCtx should help specifically for VBScript. 关于Microsoft.Windows.ActCtx的这个答案应该特别有助于VBScript。

Keep in mind that COM doesn't support static methods, so you'll have to make your Print method into an instance method. 请记住,COM不支持静态方法,因此您必须将Print方法转换为实例方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM