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.

How to: Map HRESULTs and Exceptions

Describes how to map custom exceptions to HRESULT and provides the complete mapping from each HRESULT to its comparable exception class in the .NET Framework.

Interoperating Using Generic Types

Describes which actions are supported when using generic types for COM interoperability.

Related Sections

Interoperating with Unmanaged Code

Describes interoperability services provided by the common language runtime.

Advanced COM Interoperability

Provides links to more information about incorporating COM components into your .NET Framework application.

Design Considerations for Interoperation

Provides tips for writing integrated COM components.

Remote Objects

Describes the various communications methods available in the .NET Framework for remote communications.

Community Additions