我想我可以编译一个 C# DLL,然后将它公开为一个 COM 对象,以便它可以从 VBscript 中创建对象.我只是不确定执行此操作所涉及的步骤...
I imagine I can compile a C# DLL and then expose it as a COM object so that it can be CreateObject'd from VBscript. I'm just not sure the steps involved in doing this...
这样做非常简单.但也有很多地方没那么简单.这在很大程度上取决于您的班级需要能够做什么,以及您打算如何部署它.
It can be very simple to do this. But there are a lot of places where it's not so simple. It depends a lot on what your class needs to be able to do, and how you intend to deploy it.
需要考虑的一些问题:
regasm/codebase
注册它.regasm
分配它们,但是每次(和每个地方)注册课程时它们都会有所不同.如果您需要 GUID 在安装过程中保持不变,则需要使用 Guid
属性标记成员.MarshalAs
属性标记属性和方法.InterfaceType
属性.regasm /codebase
.regasm
assign them, but they'll be different every time (and every place) the class is registered. If you need the GUIDs to remain invariant across installations, you'll need to mark members with the Guid
attribute.MarshalAs
attribute.InterfaceType
attribute.有一篇关于 COM 互操作和 .Net 的非常好的(如果过时的话)文章这里一个>.(文章谈到的很多事情,比如生成类型库,现在都是自动为您处理的.)和 Microsoft 的文档 是最新的,但不是很详细.
There's a very good (if dated) article about COM interop and .Net here. (A lot of things that article talks about, like generating type libraries, is handled for you automatically now.) And Microsoft's documentation is up to date, but not quite so detailed.
这篇关于如何从 vbScript 调用 .NET 代码 (C#/vb.net)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!