The communication between the managed and the unmanaged world can be possible in two different models supported by .NET CLR
1) Platform Invoke (Consuming unmanaged DLL methods from managed code)
2) COM Interop ( Exposing managed methods to unmanaged and vice versa using wrappers)
In my notes, I will focus more on the platform invoke which I used mostly.
Platform Invoke – This model involves invoking methods in an unmanaged DLL by creating equivalent managed prototypes. It then substitutes managed data types for unmanaged types and then marshalled across interop boundary when invoked.
COM Interop – This model is supported by some tools provided with .NET framework (tlbimp.exe and tlbexp.exe) which creates wrappers that perform the required marshalling between the managed and unmanaged world. Using this model, we can expose a managed library to unmanaged world and vice versa.
There can be detailed reading on this topic from msdn