Fun with Reflection

I was working with an application that stored some permission information in an integer in the database. Each bit of the integer represented a particular permission. The meaning of each bit came from an enumeration defined in a VB6 DLL. I needed to dig into some of these existing permission values to find out which permissions were enabled based on which bits were set in the database.

I was originally going to write up a quick VB6 app that referenced the DLL with the enumeration. I could then do a bitwise AND for each member of the enum to see if the bit was set. I thought "This would be way easier in .NET using reflection and Enum.GetValues"...

Since I usually listen to the voices in my head, I quickly created an RCW with TLBIMP and wrote up a quick app that used Enum.GetValues and Enum.GetNames to loop through the enum and display a list of permissions for me. Way easier than manually coding it with VB6 -- or digging into the Type Library API's to do the same thing in COM.

2 Comments

  • Wouldn't it be eaasier to just view the enum members in OleView's typelib decompiler or in VB's Object Browser?

  • Mattias,



    I didn't need to view the members. What I needed was some way to take the number "18723564" out of the database and figure out which bits were set to determine what member of the enumeration they applied to.

Comments have been disabled for this content.