COM Programming  «Prev  Next»

Lesson 4 What to expect
Objective Explore key course features.

Advanced COM Programming Course Features

Advanced COM (COM Fundamentals II) builds on the binary interface concepts, IUnknown rules, and ATL development skills covered in COM Fundamentals I. This lesson introduces the technical scope of the course and explains why COM knowledge remains relevant to Windows C++ developers in 2025. It also describes the learning features used throughout the course to reinforce COM programming skills.

The course covers the advanced mechanisms of COM development: containment and delegation, aggregation and the controlling unknown, out-of-process COM servers and marshalling, the COM apartment threading model, and the interface identity rules that govern all COM object interactions. Each module combines technical explanation with code examples, IDL interface definitions, and hands-on exercises built using Visual Studio 2022 and ATL.

What is COM?

The Component Object Model (COM) is a binary interface standard for software components developed by Microsoft in 1993. COM enables interprocess communication and dynamic object creation across any programming language that conforms to its binary specification. COM components communicate whether they reside in the same process, in separate processes on the same machine, or on different machines via Distributed COM (DCOM).

What distinguishes COM from earlier reuse mechanisms such as static libraries and dynamic link libraries is the level at which its contracts are defined. Traditional libraries define contracts at the source code level, making reuse dependent on the same language, compiler, or platform ABI. COM defines contracts at the binary vtable level. Any language or compiler that can produce code conforming to that binary layout can implement or consume a COM interface. This is the property that makes COM language-independent in practice.

COM's core design goal was to enable small, reusable binary components that hide internal complexity and expose only well-defined interfaces. A COM component does not expose its source code, its memory layout, or its implementation details. It exposes only the interfaces it chooses to publish, and clients interact with those interfaces through pointers that the COM runtime validates and marshals across process boundaries when necessary.

COM Object Identity and QueryInterface Rules

The IUnknown interface is the foundation of every COM object. All COM interfaces inherit from IUnknown, which defines three methods: QueryInterface, AddRef, and Release. QueryInterface is the mechanism by which a client discovers what interfaces an object supports and obtains a pointer to them. The COM specification requires that QueryInterface obey three rules that together define COM object identity:

  1. Symmetry: if QueryInterface for interface IFoo succeeds, then QueryInterface from IFoo for the original interface must also succeed and return the same pointer.
  2. Reflexivity: QueryInterface for IUnknown from any interface on an object must always succeed and must always return the same IUnknown pointer, regardless of which interface the query is issued from.
  3. Transitivity: if QueryInterface for IFoo succeeds and QueryInterface for IBar from IFoo succeeds, then QueryInterface for IBar from any other interface on the same object must also succeed.

These three rules define what it means for a set of interfaces to belong to the same COM object. They are what aggregation must preserve when inner object interfaces are exposed directly to clients via the controlling unknown mechanism. Violations of these rules produce identity inconsistencies that are difficult to diagnose at runtime and that break the assumptions that COM clients and the COM runtime make about object lifetime and interface negotiation.


Interface Negotiation and Aggregation

A well-documented design question in COM concerns the relationship between interface negotiation via QueryInterface and the aggregation reuse mechanism. The apparent tension arises because aggregation exposes the inner object's interfaces directly to clients as if they were part of the outer object's identity. This means that QueryInterface issued on the outer object must return pointers to the inner object's implementations while still satisfying the symmetry, reflexivity, and transitivity rules across the combined set of interfaces.

The controlling unknown mechanism resolves this. All QueryInterface calls on aggregated inner interfaces ultimately route through the outer object's controlling IUnknown. The outer object's QueryInterface is the single point of authority for interface identity, ensuring that the three IUnknown rules are preserved across both the outer object's own interfaces and any inner object interfaces it chooses to expose. The COM specification is internally consistent on this point: the apparent conflict between interface negotiation and aggregation arises only when an incorrect definition of interface identity is applied to the aggregation model.

COM in the Modern Windows Ecosystem

COM has evolved through several major extensions since its introduction in 1993. Understanding where COM fits in the current Windows development landscape provides context for the advanced topics covered in this course.

DCOM (Distributed COM) extends the COM binary model across network boundaries. DCOM allows a COM client to call a COM server on a remote machine transparently via RPC. DCOM was the predecessor to .NET Remoting and Windows Communication Foundation (WCF) for distributed Windows application development.

COM+ (Windows 2000) added transaction support, object pooling, role-based security, and queued components to the COM runtime. COM+ is still used in enterprise Windows applications that require distributed transaction coordination and is administered via the Component Services MMC snap-in.

ActiveX was a set of COM-based technologies designed for browser-hosted controls and container applications. ActiveX controls are deprecated in modern browsers and have been replaced by HTML5, JavaScript, and WebAssembly for web scenarios. ActiveX remains in use in legacy enterprise intranet applications.

WinRT (Windows 8, 2012) is the Windows Runtime, built on a COM-derived binary interface model. WinRT interfaces use ABI-level COM conventions: the IInspectable interface extends IUnknown and adds reflection and activation capabilities. Developers with COM knowledge can read WinRT ABI headers, implement WinRT interfaces in C++, and understand the lifetime and identity rules that govern WinRT objects. WinRT is used by the Universal Windows Platform and by modern Windows APIs including DirectX 12 and Windows ML.

.NET COM interop allows COM and .NET components to coexist in the same process. The Runtime Callable Wrapper (RCW) allows managed .NET code to consume COM objects: the RCW handles reference counting, marshalling, and lifetime management on behalf of the .NET client. The COM Callable Wrapper (CCW) exposes a .NET object as a COM server to unmanaged COM clients.

COM vs. CORBA

The Common Object Request Broker Architecture (CORBA) addressed the same distributed component communication problem as COM but from a vendor-neutral, cross-platform perspective. Where COM became the dominant component standard on Windows, CORBA found broader adoption in heterogeneous enterprise environments, particularly in telecoms, defense, and financial systems where interoperability across operating systems and hardware vendors was required.

Both COM and CORBA are largely superseded in new distributed systems development. gRPC, REST APIs, and WCF have replaced DCOM and CORBA for most distributed application work. However, COM knowledge remains essential for any developer working with the Windows platform at a low level. COM is the ABI of Windows itself: DirectX, the Windows shell, Office automation, and WinRT all use COM conventions at their interface boundary.


Why COM Knowledge Matters in 2025

COM is not a historical artifact. It is the active binary interface standard for a significant portion of the Windows API surface. Developers working in any of the following areas require COM knowledge:

  • DirectX 12 and Direct3D: every DirectX interface is a COM interface; ID3D12Device, IDXGIFactory, and all other DirectX objects implement IUnknown and are obtained via QueryInterface
  • Windows shell extensions: context menu handlers, thumbnail providers, property sheet extensions, and namespace extensions are COM servers registered in the Windows registry
  • Office automation: the Microsoft Office object model is a COM API consumed by VBA macros, C++ add-ins, and .NET applications via the RCW interop layer
  • WinRT ABI development: C++/WinRT and WRL (Windows Runtime C++ Template Library) are built on COM interface principles; IInspectable extends IUnknown and COM identity rules apply throughout
  • Legacy enterprise maintenance: large codebases in financial services, manufacturing, and government use COM+ for object pooling and distributed transaction coordination and require ongoing C++ COM expertise

Course Learning Features

Advanced COM (COM Fundamentals II) uses the following learning tools throughout the course:

  • Code examples: all COM programming concepts are illustrated with C++ code examples developed in Visual Studio 2022 using ATL, the MIDL compiler, and the Windows SDK
  • IDL interface definitions: each new interface introduced in the course is defined in IDL and compiled with MIDL to produce the proxy/stub and type library infrastructure required for out-of-process marshalling
  • Diagrams: COM object memory layout, vtable structure, IUnknown identity flow, and aggregation controlling unknown relationships are illustrated with diagrams that accompany the technical explanations
  • Quizzes: multiple-choice quizzes appear after each lesson to reinforce key COM concepts and allow you to assess your understanding before proceeding to the next topic
  • Exercises: hands-on exercises require you to build in-process COM servers using ATL, implement aggregation with correct controlling unknown plumbing, and test interface identity rules using a COM client

Throughout the course, you will find multiple-choice quizzes and hands-on exercises. These learning checks allow you to assess what you have learned and identify topics to review before proceeding.


SEMrush Software