简体   繁体   中英

Enum values from VB6 DLL do not appear in C#

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

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#.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM