Search notes:

Interoperability between managed and unmanaged code

The CLR provides two mechanisms for managed code to interoperate with unmanaged code:
Platform invoke (P/Invoke) Managed code calls functions exported from an unmanaged library (DLL)
COM interop Managed code interacts with Component Object Model (COM) COM Object]objects] through interfaces.
The .NET namespace System.Runtime.InteropServices is central to interop.

Marshaler

The task of the interop marshaler is to copy data from the CLR runtime heap to the unmanaged heap and vice versa in order to give the caller and callee the impression that they both work on the same data.
The interop marshaler always attempts to free memory allocated by unmanaged code.
This behavior complies with COM memory management rules, but differs from the rules that governs (native) C/C++.

Index