Module 2. Using COM in Your Windows Program

Module 1 of this series showed how to create a window and respond to window messages such as WM_PAINT and WM_CLOSE. Module 2 introduces the Component Object Model (COM).

COM is a specification for creating reusable software components. Many of the features that you will use in a modern Windows program rely on COM, such as:

  • Graphics (Direct2D)
  • Text (DirectWrite)
  • The Windows Shell
  • The Ribbon control
  • UI animation

(Some of the technologies on this list use a subset of COM and are therefore not "pure" COM.)

COM has a reputation for being difficult to learn. And it's true that writing a new software module to support COM can be tricky. But if your program is strictly a consumer of COM, you may find that COM is easier to understand than you expect.

This module shows how to call COM-based APIs in your program. It also describes some of the reasoning behind the design of COM. If you understand why COM is designed as it is, you can program with it more effectively. The second part of the module describes some recommended programming practices for COM.

COM was introduced in 1993 to support Object Linking and Embedding (OLE) 2.0. People sometimes think that COM and OLE are the same thing, which may be another reason for the perception that COM is hard to learn. OLE 2.0 is built on top of COM, but you don't need to know OLE to understand COM.

COM is a binary standard, not a language standard: It defines the binary interface between an application and a software component. As a binary standard, COM is language-neutral, although it maps naturally to certain C++ constructs. This module will focus on three major goals of COM:

  • Separating an object's implementation from its interface.
  • Managing the lifetime of an object.
  • Discovering the capabilities of an object at run time.

In This Section

Related Topics

Learn to Program for Windows in C++



Send comments about this topic to Microsoft

Build date: 10/5/2010