N/Direct - The .NET Interoperability Resource Center 





Most Valuable Professional

How can I prevent TlbExp from mangling my enum member names?
Written: 6/23/2002 Updated: 6/23/2002

You can't, there's currently no option to turn off that behavior. What you can do instead is edit the type library produced and correct the names.

Use the OleView tool, included with Visual Studio and the Platform SDK, to open the TLB file and get a view if the IDL source. Copy the IDL to a text file, then locate and change the enum names you want. Before you can compile this back into a type library, there are additional changes you have to make, due to a bug in OleView. Each entity in the file should have at least one custom attribute (IDL attributes is what you see enclosed in square brackets). The custom attributes contain a GUID string followed by some kind of data to be associated with it. .NET uses two custom attribute GUIDs to store information about the original assembly the type library was generated from, and what type in that assembly a certain entity corresponds to. It typically looks like this in the library attribute block.

custom(90883F05-3D28-11D2-8F17-00A0C9A6186D, MyAssembly, Version=, Culture=neutral, PublicKeyToken=null)
and for other types like this
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, MyType)
The problem is that in the decompilation process, OleView doesn't quote the strings, which causes the recompilation to fail. What you have to do is simply add double quotes around whatever appears after the GUID.
custom(90883F05-3D28-11D2-8F17-00A0C9A6186D, "MyAssembly, Version=, Culture=neutral, PublicKeyToken=null")
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "MyType")
The easiest way to find all locations is to search for these GUIDs, they are the same in all type libraries produced by TlbExp. Once this is done, you should be able to use the MIDL compiler (also included with Visual Studio and the Platform SDK) to compile the IDL source file back into a type library.