I am using an enum declared in the same namespace as one of my COM interfaces in C#.
When I view the enum in the function and object browser in Hyper Vee the enum is listed below the COM interface, but all the constants inside it have the enum name added as a prefix to it.
Example:
Enum = enumName
Const = enumName_constantName
where I want the Const to be only equal to constantName.
I have not seen this in VEE before, anyone knows why this is? Have I declared something wrong in my C# code?
public enum EnumName
{
constantName1,
constantName2
};
public interface InterfaceName
{
}
With the result that the constants being shown in VEE are shown as EnumName_constantName1, etc…
No, this is caused by a significant incompatibility between .NET enum types and the enum keyword in languages like C and C++. Those languages add the enumeration members to the global namespace. Which is actually quite a problem, it often forces you to put prefixes on the enumeration member names so they won’t collide with other identifiers. Like “constant”, as you used in your snippet.
The recently approved new C++ language standard (C++11) actually has a fix for this problem with the new enum class keyword. Which works the same way as .NET enums, they need to be prefixed by their enum type name. Coincidentally also the exact same syntax used by C++/CLI 6 years ago. It probably wasn’t an accident.
There isn’t anything reasonable that the type library exporter can do. But prefix the enumeration member with its type name. Just what you are seeing, “EnumName_constantName1”. Not doing this will invoke the horrors of identifier name collisions.
But look at the bright side, you no longer have to use that ugly “constant” prefix. The client code now can use “EnumName_Name1”. If you really, really need to fix this then you could decompile the type library into .idl with the oleview.exe program. Edit the typedef and compile it back to a .tlb with midl.exe. Otherwise a painful thing to do.