Component Object Model (COM) API Reference

This section provides comprehensive documentation for the Component Object Model (COM) APIs available in Windows. COM is a binary-standard for creating software components that can be used and reused by different applications.

Key COM Concepts

Understanding the fundamental concepts of COM is crucial for effectively utilizing its APIs. Explore the following:

  • Interfaces: Contracts defining how to interact with a COM object.
  • CLSID (Class Identifier): Globally unique identifier for a COM class.
  • IID (Interface Identifier): Globally unique identifier for a COM interface.
  • CoCreateInstance: A primary function for creating COM object instances.
  • QueryInterface: Method for discovering and accessing supported interfaces on an object.
  • Reference Counting: Mechanism for managing the lifetime of COM objects.

Core COM Functions

Here are some of the most frequently used COM functions:

CoInitializeEx

Description: Initializes the COM library for the current thread and sets the concurrency model.

HRESULT CoInitializeEx(
  LPVOID pvReserved,
  DWORD  dwCoInit
);

Parameters:

  • pvReserved: Reserved; must be NULL.
  • dwCoInit: The concurrency model. See COINIT constants.

Return Value: S_OK if successful, or one of the error codes.

CoUninitialize

Description: Uninitializes the COM library for the current thread.

void CoUninitialize(void);

Return Value: None.

CoCreateInstance

Description: Creates a single uninitialized object of the specified class.

HRESULT CoCreateInstance(
  REFCLSID clsid,
  LPUNKNOWN pUnkOuter,
  DWORD     dwClsContext,
  REFIID    riid,
  LPVOID    *ppv
);

Parameters:

  • clsid: The CLSID of the object to be created.
  • pUnkOuter: If NULL, the object does not support aggregation.
  • dwClsContext: The context in which the code that creates the executable code for the object will run.
  • riid: The IID of the interface to be used to communicate with the newly created object.
  • ppv: Address of pointer variable that receives the interface pointer.

Return Value: S_OK if successful, or one of the error codes.

Common COM Interfaces

Key interfaces for COM programming:

See Also