Partager via


Simulating COM Interfaces 

The COM callable wrapper (CCW) exposes all public, COM-visible interfaces, data types, and return values to COM clients in a manner that is consistent with COM's enforcement of interface-based interaction. For a COM client, invoking methods on a .NET Framework object is identical to invoking methods on a COM object.

To create this seamless approach, the CCW manufactures traditional COM interfaces, such as IUnknown and IDispatch. As the following illustration shows, the CCW maintains a single reference on the .NET object that it wraps. Both the COM client and .NET object interact with each other through the proxy and stub construction of the CCW.


Com interfaces and the COM callable wrapper

COM interfaces

In addition to exposing the interfaces that are explicitly implemented by a class in the managed environment, the .NET Framework supplies implementations of the COM interfaces listed in the following table on behalf of the object. A .NET class can override the default behavior by providing its own implementation of these interfaces. However, the runtime always provides the implementation for the IUnknown and IDispatch interfaces.

Interface Description

Idispatch

Provides a mechanism for late binding to type.

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

Enables COM clients to gain access to the ITypeInfo interface implemented by a managed class.

IsupportErrorInfo

Enables a COM client to determine whether the managed object supports the IErrorInfo interface. If so, enables the client to obtain a pointer to the latest exception object. All managed types support the IErrorInfo interface.

ItypeInfo

Provides type information for a class that is exactly the same as the type information produced by Tlbexp.exe.

Iunknown

Provides the standard implementation of the IUnknown interface with which the COM client manages the lifetime of the CCW and provides type coercion.

A managed class can also provide the COM interfaces described in the following table.

Interface Description

The (_classname) class interface

Interface, exposed by the runtime and not explicitly defined, that exposes all public interfaces, methods, properties, and fields that are explicitly exposed on a managed object.

IConnectionPoint and IconnectionPointContainer

Interface for objects that source delegate-based events (an interface for registering event subscribers).

IdispatchEx

Interface supplied by the runtime if the class 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

Interface for collection-type classes, which enumerates the objects in the collection if the class implements IEnumerable.

See Also

Concepts

COM Callable Wrapper
Introducing the Class Interface
Exposing .NET Framework Components to COM