1

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

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • 1
    maybe enums are internal? make them public. – M.kazem Akhgary Jun 11 '15 at 12:06
  • Object Browser just doesn't display them. You can't fix the way it works. You could simply right-click the enum name in your code and use "Go To Definition". – Hans Passant Jun 11 '15 at 12:41
  • @M.kazem Akhgary - but the enum type name is visible (public), its just the values which are not. Is there some way to qualify the visibility of the values? Also the values do show up in the VB6 object viewer, just not the VS2010 one. Thanks – StayOnTarget Jun 11 '15 at 17:08
  • @HansPassant thanks I've updated the question with more info. – StayOnTarget Jun 11 '15 at 17:12
  • Well, try it by adding a reference to c:\windows\system32\shell32.dll and have a look at ShellSpecialFolderConstants. That works fine, I can't guess how that VB6 type library got screwed up. Try using the telephone. – Hans Passant Jun 11 '15 at 17:26
  • in one of my projects i tried to decompile dll file and i had the same problem. enums with no values. i have no idea why, you can create a library with enum yourself. and then try to decompile it and see what happens. Also note that Go To Definition will decompile the file if its inside dll. (im **not** saying decompile will clear out enum values) but ill let you know if i find solution... – M.kazem Akhgary Jun 11 '15 at 17:38
  • Have a look at http://stackoverflow.com/questions/11647647/how-to-expose-an-enum-defined-in-a-com-library-via-interop-as-the-return-type-of - maybe something there applies to this issue? – rskar Jun 11 '15 at 18:04
  • @rskar thanks for the link - that showed an example which was not having the same problem I am having, which led to some further experimentation. – StayOnTarget Jun 12 '15 at 13:04
  • @HansPassant - sorry but I don't understand the telephone comment? – StayOnTarget Jun 12 '15 at 13:05

1 Answers1

0

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

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • I was considering editing this question to ask about how to use values with spaces in C#, but felt that was really a separate question. So I created http://stackoverflow.com/questions/30803987/is-it-possible-to-use-vb6-enums-which-have-values-with-spaces-in-c instead. – StayOnTarget Jun 12 '15 at 13:12