问题创建一个仅包含枚举的COM库 [英] Problem creating COM-library only containing enum's

查看:139
本文介绍了问题创建一个仅包含枚举的COM库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个COM-互操作的项目。一些代VB和C ++的ATL COM项目,C#和.NET互操作。当我定义.NET枚举和他们做标记有ComVisible特性,它们会暴露只是Typelib.EnumValue的Typelib.EnumType_EnumValue enstead。该类型库导出这样做是为了确保该值名称是唯一的。但我知道,我的所有枚举的是独一无二的,所以我不想下划线。也有很多的客户端code,需要改变,如果我没有摆脱下划线的。

I'm am doing a COM-interop project. Substituting some VB and C++ ATL COM projects with C# and .NET Interop. When i define enumerations in .NET and they are made ComVisible, they get exposed as Typelib.EnumType_EnumValue enstead of just Typelib.EnumValue. The typelib exporter does this to ensure that the value names are unique. But i know that all my enum's are unique, so i don't want the underscores. Also there is a lot of client code that needs alteration if i don't get rid of the underscores.

要找到解决这个问题,我已经定义枚举在一个IDL文件并创建一个类型库和.NET互操作来源于此。

To find a solution to this problem, i have defined the enum's in an IDL-file and creating a typelib and .Net interop from this.

[
  uuid(64893FD4-359D-46B9-BC1E-48C055796104),
  version(1.0),
  helpstring("ABC"),
  helpfile("AAA.chm"),
  helpcontext(0x00000001)
]

library EnumTypeLib
{
    importlib("stdole2.tlb");
    typedef [uuid(8FF85069-C4E2-4540-A277-4C0F3C19B807), helpstring("MyEnum"), helpcontext(0x00000066)]
    enum MyEnum {
        Value1 = 0,
        Value2 = 1,
    } MyEnum;
};

我创建MIDL.EXE一个类型库产生一个TLB文件。

I create a typelibrary with MIDL.exe which produces a tlb-file.

和我创建的tlbimp.exe是装配。使用相同的密钥与其他互操作程序集签名的程序集。

And i create an assembly with the tlbimp.exe. signing the assembly with the same key as the other Interop assemblies.

TLBIMP OpenStructureAdapterEnum.tlb /keyfile:KeyFile.snk

tlbimp OpenStructureAdapterEnum.tlb /keyfile:KeyFile.snk

然后我注册regasm.exe大会 该组件看起来很好,并没有包含下划线的枚举。但问题是,不能看到从OLE / COM对象查看器或VBA或VB6的COM库。当我引用枚举从另一个COM暴露的组件,包含对枚举的接口部分,被暴露只供方法。

Then i register the assembly with regasm.exe This assembly looks fine and contains the enum without underscores. But the problem is that a can't see the COM-library from OLE/COM Object Viewer or from VBA or VB6. And when i reference the enum from another COM-exposed assembly, the part of the interface containing references to the enum, gets exposed as resticted methods.

[restricted] void Missing7();
[restricted] void Missing8();
[restricted] void Missing9();
[restricted] void Missing10();

如何创建一个只包含枚举(无下划线)一个COM库,并从其他.NET互操作程序集引用这些?

How can i create a COM library containing only enums (without underscores) and referencing these from other .net Interop assemblies?

推荐答案

我已经做到了这一点:

在.NET中,我创建了一个名为PermissionControlLib一个COM可见的库这样的枚举:

In .NET, I created a COM visible library named PermissionControlLib with an enum like this:

public enum NetOperations
{
   Oper1,
   Oper2,
   Oper3
}

在VB6中,我创建了另一个枚举是这样的:

In VB6, I've created another enum like this:

Public Enum VBOperations
   Oper1=NetOperations.NetOperations_Oper1,
   Oper2=NetOperations.NetOperations_Oper2,
   Oper3=NetOperations.NetOperations_Oper3
End Enum

用法:

Dim ud as PermissionControlLib.IUser
Set ud = New User
Dim b as Boolean
b = ud.HasPermissionInOperation(VbOperations.Oper1)

这篇关于问题创建一个仅包含枚举的COM库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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