views:

29

answers:

1

We know that .NET framework class encapsulate the Win32 API, now I am wondering how the .NET framework class call Win32 API?

Ways I know so far:

  1. Through P/Invoke
  2. VC++/CLI
  3. Both 1 and 2

Anybody know the answer?

+3  A: 

Most framework classes use P/Invoke if they need to call unmanaged APIs. Fire up Reflector on System.Windows.Forms and you'll see classes called NativeMethods and UnsafeNativeMethods which do a lot of P/Invoke. Similarly System.Drawing has a SafeNativeMethods class which declares all the GDI+ P/Invokes.

The other main interop method you don't mention is COM interop. I don't know how widely this is used within the framework, but I'd guess that some of the WMI (System.Management) stuff uses it pretty heavily, plus of course WinForms ActiveX support.

itowlson