|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
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.
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.
Describes which actions are supported when using generic types for COM interoperability.