다음을 통해 공유


Marshaling Selected Interfaces 

The primary goal of the runtime callable wrapper (RCW) is to hide the differences between the managed and unmanaged programming models. To create a seamless transition, the RCW consumes selected COM interfaces without exposing them to the .NET client, as shown in the following illustration.


COM interfaces and the runtime callable wrapper

RCW With Interfaces

When created as an early-bound object, the RCW is a specific type. It implements the interfaces that the COM object implements and exposes the methods, properties, and events from the object's interfaces. In the illustration, the RCW exposes the INew interface but consumes the IUnknown and IDispatch interfaces. Further, the RCW exposes all members of the INew interface to the .NET client.

The RCW consumes the interfaces listed in the following table, which are exposed by the object it wraps.

Interface Description

IDispatch

For late binding to COM objects through reflection.

IErrorInfo

Provides a textual description of the error, its source, a Help file, Help context, and the GUID of the interface that defined the error (always GUID_NULL for .NET classes).

IProvideClassInfo

If the COM object being wrapped implements IProvideClassInfo, the RCW extracts the type information from this interface to provide better type identity.

IUnknown

For object identity, type coercion, and lifetime management:

  • Object identity

    The runtime distinguishes between COM objects by comparing the value of the IUnknown interface for each object.

  • Type coercion

    The RCW recognizes the dynamic type discovery performed by the QueryInterface method.

  • Lifetime management

    Using the QueryInterface method, the RCW gets and holds a reference to an unmanaged object until the runtime performs garbage collection on the wrapper, which releases the unmanaged object.

The RCW optionally consumes the interfaces listed in the following table, which are exposed by the object it wraps.

Interface Description

IConnectionPoint and IConnectionPointContainer

The RCW converts objects that expose the connection-point event style to delegate-based events.

IDispatchEx

If the class implements IDispatchEx, the RCW implements IExpando. The IDispatchEx interface is an extension of the IDispatch interface that, unlike IDispatch, enables enumeration, addition, deletion, and case-sensitive calling of members.

IEnumVARIANT

Enables COM types that support enumerations to be treated as collections.

See Also

Concepts

Runtime Callable Wrapper
Qualifying .NET Types for Interoperation

Other Resources

Assembly to Type Library Conversion Summary