Runtime Callable Wrappers

The semantics of object creation and maintenance are very different under COM and .NET. In order to invoke a COM component we need to know the class IDs and interface IDs of the component.We also need to call the AddRef() and Release() methods on the COM component to maintain its lifetime.The AddRef() method allocates memory for a COM component and the Release() method will release the memory resources. Unfortunately managed components are not aware of the IUnknown interface and it is not practical for the managed components to explicitly support this interface solely to support legacy COM components.

What we need is seamless support from the .NET runtime that allows managed components to transparently invoke COM components in the exact manner as it would invoke a managed component.This is done by creating a managed wrapper around the COM object, called the Runtime Callable Wrapper (RCW). The RCW takes care of the incompatibilities between .NET and COM and acts as a proxy that makes the COM component accessible to managed components. Essentially the RCW is the bridge between COM and .NET assemblies, acting as a COM component on one side and as a managed component on the other. Since there is now an extra layer, there will be a performance hit while using wrappers. Figure 14.5 shows where RCWs fit into the .NET Framework.

Figure 14.5 Runtime Callable Wrapper Architecture

Unmanaged EnvĂ­ronemnt

IUnknown

MyInterface1 ( MyInterface2 ( FooInterface (

Win 32 COM DLL

Common Language Runtime Managed Environemnt

Runtime Callable Wrapper

Meta Data

MS IL FooInterface

.NET Assembly

Meta Data

0 0

Post a comment

  • Receive news updates via email from this site