0Pricing
C# Academy · Lesson

COM Interop & Runtime Callable Wrappers

Consume COM components from C# with RCW, import type libraries, and handle HRESULT exceptions.

What Is COM Interop?

COM (Component Object Model) is Microsoft's legacy binary interface standard, still used by Office, Windows Shell, DirectX legacy APIs, and many enterprise tools. .NET can consume COM components via interop wrappers that translate between managed objects and COM interfaces.

Runtime Callable Wrappers (RCW)

When you access a COM object from .NET, the CLR creates a Runtime Callable Wrapper (RCW) — a managed proxy that wraps the COM object. The RCW handles reference counting (AddRef/Release), apartment threading, and marshaling between COM and .NET types automatically.

// The RCW is created automatically when you instantiate a COM class
// via a registered ProgID or CLSID

// Example: create an Excel Application COM object
Type excelType = Type.GetTypeFromProgID("Excel.Application")!;
object excelApp = Activator.CreateInstance(excelType)!;

// excelApp is an RCW — the CLR wraps the underlying IDispatch COM object
// COM AddRef is called; CLR tracks references
Console.WriteLine(excelApp.GetType().Name); // ApplicationClass

All lessons in this course

  1. P/Invoke Fundamentals
  2. LibraryImport & Source-Generated P/Invoke
  3. Unsafe Code, Pointers & Fixed Buffers
  4. COM Interop & Runtime Callable Wrappers
← Back to C# Academy