I wanted to prove that I can take any external COM Interface DLL and make it into a C# class object that can be used internally instead of Dynamically linking it.
When you add a resource COM interface, you actually dynamically link your project with a DLL file that will later show up in your project compilation output directory ..\bin\debug or ..\bin\release. In my opinion, this is not clean coding especially when you are using external DLLs that you have a license to use but don't want others to use them without a license. There are a few applications out there that can 'embed' your DLL files inside your executable, but those are just wrappers. What I'd like to demonstrate here is how we go back from Managed C# coding to the beginning of it all: Binary..
What I have done is to create a simple [took me less than 2 hours] COM/DLL parser that can take any external COM *.dll resource file and convert it into Binary and then back into Managed C# code using the '
System' and '
System.Reflection' Namespaces and even add the COM classes and functions as C# methods.
The main objective is to convert the entire DLL into managed code!
The parser is not complete, of course, since it's just an example, but it is living proof that even with managed code you can access and embed the low-level binaries. So it's nice and you may (or not) even learn something. I hope someone will see this as a challenge and continue this parser, since it's a lot of 'dirty work', it's not hard enough to be interesting, and I'm too lazy to complete all the options (interfaces, variables,
enums, etc... and then recursion of it all (classes inside classes and so on...)). But the main engine is already built, so...
Using the Code
I added the entire solution, and a demo executable. The entire parser is just a small class that uses the
System.Reflection.Assembly to rebuild the DLL file back from binary after I embed the binary itself inside the C# file. After that, you may parse and use the DLL classes and methods as if you are using any other C# method, internally.
Points of Interest
This is a project output example, the highlighted file is the Shell32.dll:
This is after I parsed and saved the DLL as a CS file, I created Shell32.cs that should maintain all the functionality of the DLL file:
This is a screenshot of the compiler, loading the Shell32.dll file:
This is a screenshot of the compiler, after it parsed the Shell32.dll file:
Then you save the 'DLL' file as a C# Shell32.cs file:
And it's that simple.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.