如何从 VBScript 调用 C# DLL 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/769332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:26:17  来源:igfitidea点击:

How to call C# DLL function from VBScript

c#dllvbscriptfunction-calls

提问by abatishchev

I have my script on server, so I do not have UI interaction available and have to use DLL instead of console application.

我在服务器上有我的脚本,所以我没有可用的 UI 交互,必须使用 DLL 而不是控制台应用程序。

How to call a function in C# DLL from VBScript?

如何从 VBScript 调用 C# DLL 中的函数?

How do I make my DLL to be COMVisible? Do I have to register it?

我如何使我的 DLL 成为COMVisible?我必须注册吗?

采纳答案by Darin Dimitrov

You need to mark your assembly as COM visible by setting the COMVisibleAttributeto true (either at assembly level or at class level if you want to expose only a single type).

您需要通过将COMVisibleAttribute设置为 true来将您的程序集标记为 COM 可见(如果您只想公开一种类型,则在程序集级别或在类级别)。

Next you register it with:

接下来你注册它:

regasm /codebase MyAssembly.dll

and finally call it from VBScript:

最后从 VBScript 调用它:

dim myObj
Set myObj = CreateObject("MyNamespace.MyObject")

回答by danish

Yes you will need to set the ComVisibleattribute to true and then register the assembly using regasm or regsvcs along with tlbexp. Then you can use Server.CreateObjectand sail through.

是的,您需要将该ComVisible属性设置为 true,然后使用 regasm 或 regsvcs 以及 tlbexp 注册程序集。然后你可以使用Server.CreateObject和航行。