What is Marshaling in .NET - ablealias/asp.net GitHub Wiki
Marshaling is the process of creating a bridge between managed code and unmanaged code
; it is the homer that carries messages from the managed to the unmanaged environment and reverse. It is one of the core services offered by the CLR (Common Language Runtime.). Because much of the types in unmanaged environment do not that support in managed environment, you need to create conversion routines that convert the managed types into unmanaged and vice versa; and that is the marshaling process. We call .NET code managed because it is controlled (managed) by the CLR. Other code that is not controlled by the CLR is called unmanaged.
Why Marshaling?
You already know that there is no such compatibility between managed and unmanaged environments. In other words, .NET does not contain such the types HRESULT, DWORD, and HANDLE that exist in the unmanaged code. Therefore, you need to find a .NET substitute or create your own if needed. That is what called marshaling
.
Marshaling comes handy when you are working with unmanaged code, whether you are working with Windows API or COM components. It helps you inter-operating (i.e. working) correctly with these environments by providing a way to share data between the two environments.