.NET Disassemblers

I was given the task of creating my first Primary Interop Assembly for one of our existing ActiveX products at work. This was supposed to be an easy chore, and I am sure that it is... for most people. My problem was that I didn't have very much know-how about the internals of COM. Most all of the help files that I sifted through assumed that the author of the PIA had knowledge of COM. This was not the case for me.

My initial attempts was using tlbimp/ildasm/ilasm/regasm commands in that order to create/disassemble/modify/reassemble the interop assemblies and register them on the clients machine. I did this for probably 1 full week and was getting no where fast. A good buddy of mine came to tell me that there were other means of doing this without mucking through IL code. The idea is to disassemble the assembly into C# code. After a couple of days I found that there are a lot of very handy tools for creating C# code from a .NET assembly. Unfortunately none of them generate a perfect wrapper like I had hoped. Some of the tools I used were as follows:

1.) COMtoNET - Aurigma.com 
2.) SalamderIt - RemoteSoft.com
3.) Reflector - Lutz Roeder
4.) ILDasm - Microsoft .NET Framework (when all else fails)

Through all of these attempts I found that one of our methods was always requiring a parameter to be passed by reference. This was extremely ugly when coding against .NET because it forces the user to create a temporary object to hold the indexing value just to call the method. One of our developers was helping me with this issue and showed me that (in the COM world) the parameter was being passed as a pointer to a VARIANT, thus the wrapper was forcing the object to be passed by reference. This is due to the Default Marshaling of Objects in COM Interop from managed to unmanaged code. The fix was to change the argument to be passed as a VARIANT, rather than a pointer to a VARIANT. Good thing I found that one... :) Thanks Chris.

Bottom line is this: COM interop is a very cool thing, and it is very evident that Microsoft developers ensured all work done in COM did not get lost. I just wish I had known a little bit more knowledge about COM before I started this project. The best thing I took away from this project was finding out the internals of ActiveX and all the complexities that go along with it. I am smarter now than I was 3 weeks ago. :)

Print | posted on Monday, July 19, 2004 1:37 PM