ICustomMarshaler Interface
Collapse the table of content
Expand the table of content

ICustomMarshaler Interface

Designed to provide custom wrappers for handling method calls.

For a list of all members of this type, see ICustomMarshaler Members.

[Visual Basic]
Public Interface ICustomMarshaler
public interface ICustomMarshaler
public __gc __interface ICustomMarshaler
public interface ICustomMarshaler


To use a custom marshaler, you must apply the MarshalAsAttribute to the parameter or field being marshaled. You must also pass UnmanagedType.CustomMarshaler to its constructor and specify the MarshalType. The attribute identifies the appropriate custom marshaler to activate the appropriate wrapper. The common language runtime's interop service then examines the attribute and creates the custom marshaler when the argument is marshaled. It calls on the custom marshaler's MarshalNativeToManaged and MarshalManagedToNative methods to activate the correct wrapper to handle the call.

In addition to implementing the ICustomMarshaler interface, custom marshalers must implement a static (Shared in Visual Basic) method called GetInstance that accepts a String as a parameter and has a return type of ICustomMarshaler. This static (Shared in Visual Basic) method is called by the common language runtime's COM interop layer to instantiate an instance of the custom marshaler. The String passed to GetInstance is a cookie that the method can use to customize the returned custom marshaler.


Namespace: System.Runtime.InteropServices

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Mscorlib (in Mscorlib.dll)

See Also

ICustomMarshaler Members | System.Runtime.InteropServices Namespace

© 2015 Microsoft