2

How does .NET allow API exploration of compiled DLLs?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
RCIX
  • 38,647
  • 50
  • 150
  • 207

4 Answers4

7

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.

Jon Skeet
  • 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
  • 1
    Actually, 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
1

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.

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
0

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.

Dave Van den Eynde
  • 17,020
  • 7
  • 59
  • 90
-1

One Word: Reflector

Abhijeet Patel
  • 6,562
  • 8
  • 50
  • 93