Enum values from VB6 DLL do not appear in C#

410 views Asked by At

We have a VB6 DLL which includes several enum definitions. We have loaded the VB6 DLL as a reference in a C# project.

In the Visual Studio 2010 object browser, all the VB6 classes are visible, as are the enum names. However, the enum values are not shown, and also are not listed when using intellisense within C# code. However the enum name does come up from intellisense, as do all the class names and class methods, properties etc. that I have tried. So only the values seem to be left out.

If I click the enum name in a code window and select Go To Definition, I get something like this:

namespace DLLName
{
    [Guid("3DD0C797-2BF0-4A7A-8E1E-83E3095CB3AE")]
    public enum EnumName
    {
    }
}

Which shows the same thing - enum exists with no values.

So the question is - where did the enum values go, and is there something we can do to get them to show up?

Note - I could modify the VB6 DLL if necessary.

Thanks

1

There are 1 answers

1
StayOnTarget On BEST ANSWER

The enum values had spaces in the value names in VB6, and this causes them to be omitted from the enum definition in C#.

In VB6, you can declare enum values which have names with spaces in them, using a special square bracket syntax. Examples:

Public Enum TestEnumNoSpaces
    EnumA
    EnumB
    EnumC
End Enum

Public Enum TestEnumWithSpaces
    [Enum A]
    [Enum B]
    [Enum C]
End Enum

If you compile this to a DLL and load it as a reference in Visual Studio 2010, in the object browser both enums are visible. However, the enum values are not shown.

Most of the enums in the DLL I am using have enums with spaces in the names. This has been a common naming convention. But fortunately, there were a few which did not use this format and I noticed their values were showing up in C#.