是否可能暴露一个C#枚举到COM Interop调用者,如果是,如何? [英] Is it possible to expose a C# Enum to COM Interop callers, and if so, how?

查看:128
本文介绍了是否可能暴露一个C#枚举到COM Interop调用者,如果是,如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过COM Interop调用的托管程序集。像一个VBScript客户端,一个Perl客户端,等等。

I have a managed assembly that gets called via COM Interop. Like a VBScript client, a Perl client, and so on.

类用

[ClassInterface(ClassInterfaceType.AutoDual)]
[GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000E")]
[ComVisible(true)]

然后当然我做regasm的事情,所有的方法工作很好。

Then of course I do the regasm thing, and all the methods work just fine.

但是也有枚举类型组装。我想使用符号名COM应用程序,用于枚举值。

But there are also enum types in the assembly. I'd like to use symbolic names COM applications, for the enum values.

如何通过COM interop暴露枚举?我只需要添加这些属性?

How do I expose the enums via COM interop? Do I just need to add these attributes?

[GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000E")]
[ComVisible(true)]

然后,如何在VBScript中引用这些符号名?我没有看到OleView中的枚举类型。 (我应该怎么办?)我看到OleView中的所有其他类型。

And then, how do I reference those symbolic names in VBScript? I don't see the enum types in OleView. (Should I?) I see all the other types in OleView.

推荐答案

VBScript和其他后期绑定的客户端使用IDispatch调用对象上的方法。因此,这些语言不能访问typelib中的类型信息 - 它们只是从GUID创建一个对象,获取一个IDispatch指针,并按名称开始调用方法。

VBScript and other late-bound clients use IDispatch to call methods on objects. As such, these languages don't have access to type information in the typelib -- they just create an object from a GUID, get an IDispatch pointer back, and start calling methods by name.

我不确定问题的COM interop部分,但即使枚举确实显示在OleView中,您也无法直接使用它们。

I'm unsure of the COM interop part of the question, but even if the enums did show in OleView, you wouldn't be able to use them directly.

然而,如果你能够在typelib发布枚举,我之前写了一个工具,可以生成一个脚本文件(vbs或js)包含typelib的所有枚举作为常量。

However, if you are able to publish the enums in the typelib, I wrote a tool eons ago that can generate a script file (vbs or js) containing all the enums from a typelib as constants.

请参阅: http://www.kontrollbehov.com/ tools / tlb2const /

这篇关于是否可能暴露一个C#枚举到COM Interop调用者,如果是,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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