How does .NET allow API exploration of compiled DLLs?
-
1This question shouldn't be closed, it's related to this question: http://stackoverflow.com/questions/1507743/whats-the-rationale-behind-headers/1507755#1507755 – Dave Van den Eynde Oct 02 '09 at 05:32
-
1Closing? How is this "Not a Real Question?" – Robert Harvey Oct 02 '09 at 05:44
4 Answers
Because the DLL contains metadata about all the types, methods etc. Even the actual code is in IL rather than native code.
Basically a .NET binary is still at a higher level than a native binary, and contains a lot more information about what's in there. That's what allows Reflection to work.

- 1,421,763
- 867
- 9,128
- 9,194
-
So, is it accurate to say that C# gets compiled then? I'm asking because if I understand what you're saying, the IL then gets interpreted, right? – Esteban Araya Oct 02 '09 at 05:38
-
If i understand it correctly, IL is JIT compiled to the proper machine code as necessary. – RCIX Oct 02 '09 at 05:42
-
1Actually, both are true. On almost all .NET implementations, it is JIT compiled. But on "Micro Framework" it is interpreted. You aren't hugely likely to see Micro Framework much ;-p – Marc Gravell Oct 02 '09 at 05:45
-
Mono also has a bytecode interpreter, and IIRC can be forced to use it via command line switches. – Pavel Minaev Oct 02 '09 at 05:51
-
A "mixed" assembly can contain both managed and unmanaged code. – Dave Van den Eynde Oct 02 '09 at 06:47
I'm not sure if that is what you are asking about, but I can only recommend the free tool .NET Reflector that lets you explore any compiled .NET assembly.
These days, I use it much more than I use even the published MSDN documentation, because it's much faster to navigate around in, and more informative to boot.

- 225,310
- 48
- 427
- 736
-
2
-
I don't think it was apparent just what he was asking about, which was also why I qualified my answer by "I'm not sure if that is what you are asking about". – Mark Seemann Oct 02 '09 at 07:39
It depends.
A DLL contains a list of functions exported, but these can be simply assigned a number, a name, or they can be assigned a mangled C++ name. The latter can give some insight in the function's parameters, but data structures, calling conventions and other required attributes are generally not documented.
If it's a COM DLL, there's a possibility that it contains a Type Library as a resource, but this is not guaranteed. In that case, .NET can import the library quite automatically.
A Type Library can also be included in a non-COM DLL, but this is not a widespread practice.
If you have a compiled DLL designed to be called from a non-COM, non-managed environment, you'll need to translate the header files that should be included with the DLL.

- 17,020
- 7
- 59
- 90
-
I believe the question is specific to .NET, so the C++/COM side - while interesting and accurate - doesn't really apply. – Marc Gravell Oct 02 '09 at 05:41
-
This question is a response to my comment about another question regarding headers, so no, I don't think it's specific to .NET DLL's. – Dave Van den Eynde Oct 02 '09 at 06:46
One Word: Reflector

- 6,562
- 8
- 50
- 93
-
Are you saying that Reflector will not provide exploration of metadata? – Abhijeet Patel Oct 02 '09 at 16:59