Interop Marshaling

The audience for this section includes programmers who use platform invoke, COM interop, or both to marshal data. Certain marshaling rules and default data types differ between the two mechanisms:

  • If you use platform invoke, this section provides examples for marshaling strings, arrays, classes, structures, unions, and various miscellaneous types.
  • If you use COM interop, this section describes how to customize interop wrappers.

Interop marshaling governs how data is passed in method arguments and return values between managed and unmanaged memory during calls. Interop marshaling is a run-time activity performed by the common language runtime's marshaling service.

This section provides an overview of the interop marshaling service and presents detailed information about how data types that have different or ambiguous representations in unmanaged memory are marshaled. It also describes how to apply the MarshalAsAttribute attribute and use methods exposed by the Marshal class to alter the default marshaling behavior.

In This Section

Interop Marshaling Overview
Describes the marshaling service, its relationship to COM marshaling, and its role in remote communications.
Default Marshaling Behavior
Describes the rules that the interop marshaling service uses to marshal data.
Marshaling Data with Platform Invoke
Describes how to declare method parameters and pass arguments to functions exported by unmanaged libraries.
Marshaling Data with COM Interop
Describes how to customize COM wrappers to alter marshaling behavior.

Related Topics

Interoperating with Unmanaged Code
Describes how to use COM interop and platform invoke.
Advanced COM Interop
Describes COM interop concepts and conversion rules.
Design Considerations for Interoperation
Provides tips for writing integrated COM types.
Accessing Objects in Other Application Domains Using .NET Remoting
Describes how to establish communication between managed objects that run in different processes.