System.Runtime.InteropServices.ICustomMarshaler Interface

Assembly: Mscorlib.dll
Namespace: System.Runtime.InteropServices
Summary
Designed to provide custom wrappers for handling method calls.
C# Syntax:
public interface ICustomMarshaler
Remarks
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 MarshalAsAttribute.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 ICustomMarshaler.MarshalNativeToManaged and ICustomMarshaler.MarshalManagedToNative methods to activate the correct wrapper to handle the call.

In addition to implementing the ICustomMarshaler interface, custom marshalers must implement a static method called GetInstance that accepts a String as a parameter and has a return type of ICustomMarshaler. This static 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.

See also:
System.Runtime.InteropServices Namespace

System.Runtime.InteropServices.ICustomMarshaler Member List:

Public Methods
CleanUpManagedData
CleanUpNativeData Performs necessary cleanup of the unmanaged data when it is no longer needed.
GetNativeDataSize Returns the size of the native data to be marshaled.
MarshalManagedToNative
MarshalNativeToManaged

System.Runtime.InteropServices.ICustomMarshaler Member Details

Method: CleanUpManagedData(
   object ManagedObj
)
Summary
Performs necessary cleanup of the managed data when it is no longer needed.
C# Syntax:
void CleanUpManagedData(
   object ManagedObj
);
Parameters:

ManagedObj

The managed object to be destroyed.

Return to top


Method: CleanUpNativeData(
   IntPtr pNativeData
)
Summary
Performs necessary cleanup of the unmanaged data when it is no longer needed.
C# Syntax:
void CleanUpNativeData(
   IntPtr pNativeData
);
Parameters:

pNativeData

A pointer to the unmanaged data to be destroyed.

Return to top


Method: GetNativeDataSize()
Summary
Returns the size of the native data to be marshaled.
C# Syntax:
int GetNativeDataSize();
Return Value:
The size in bytes of the native data.

Return to top


Method: MarshalManagedToNative(
   object ManagedObj
)
Summary
Converts the managed data to unmanaged data.
C# Syntax:
IntPtr MarshalManagedToNative(
   object ManagedObj
);
Parameters:

ManagedObj

The managed object to be converted.

Return Value:
Returns the COM view of the managed object.

Return to top


Method: MarshalNativeToManaged(
   IntPtr pNativeData
)
Summary
Converts the unmanaged data to managed data.
C# Syntax:
object MarshalNativeToManaged(
   IntPtr pNativeData
);
Parameters:

pNativeData

A pointer to the unmanaged data to be wrapped.

Return Value:
Returns the managed view of the COM data.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.