Updated: July 10, 2020 (May 26, 2003)

  Charts & Illustrations

Mixing Managed and Unmanaged Code

My Atlas / Charts & Illustrations

262 wordsTime to read: 3 min

The interoperability features of the Common Language Runtime (CLR) allow developers to mix managed code with existing unmanaged code in COM components (as well as code in Win32 dynamic link libraries, or DLLs).

When a managed code component calls code in a COM component (top) the CLR generates a run-time callable wrapper (RCW). This RCW acts as a proxy, or intermediary, for the unmanaged COM component. The RCW handles all interaction between the managed component and the COM component, including (but not limited to) the following:

  • Translating and moving data between the CLR and the COM environments
  • Releasing the memory and other resources of the wrapped COM component when the managed code component is reclaimed by the CLR garbage-collection process
  • Translating errors from COM error return codes (HRESULT values) into CLR errors (called exceptions).

When a COM component calls a .NET component written in managed code (bottom), the CLR again generates a wrapper, in this case a COM callable wrapper (CCW). Similar to the RCW, the CCW acts as a proxy or intermediary between the unmanaged COM code and the managed code. The CCW also implements the standard set of functions that are required of COM components so that the managed code component appears to be a normal COM component.

Atlas Members have full access

Get access to this and thousands of other unbiased analyses, roadmaps, decision kits, infographics, reference guides, and more, all included with membership. Comprehensive access to the most in-depth and unbiased expertise for Microsoft enterprise decision-making is waiting.

Membership Options

Already have an account? Login Now