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.
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;
};
I create a typelibrary with MIDL.exe which produces a tlb-file.
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
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();
How can i create a COM library containing only enums (without underscores) and referencing these from other .net Interop assemblies?