Home > Articles > Programming

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Implementing QueryInterface

QueryInterface is the fundamental mechanism by which a COM object provides pointers to its interfaces. It responds to a client's request by returning the specified interface pointer. Following are some recommendations for using QueryInterface:

  • QueryInterface must check the incoming IID to see whether the request is for a supported interface. IsEquallD is a utility function declared in guiddef.h that simplifies comparing IIDs.
  • If the object supports the requested interface, QueryInterface calls AddRef to increment the object's reference count and returns the requested interface pointer. To return the point, QueryInterface casts this pointer to the requested interface type. This cast is required because of the way in which C++ handles multiple inheritances.
  • When a client queries for IUnknown, an object must always return the same IUnknown pointer, regardless of which interface called QueryInterface.

The basic process of implementing UMDF callback interfaces is similar to that of IUnknown. Most of the implementation details are governed by the requirements of the individual methods.

Summary

In this series of articles, we've considered the architecture of user mode drivers and the design, development, and debugging processes for creating user mode drivers. In my book Windows 7 Device Driver, the driver programmer from start to finish is developing user mode drivers. The book's appendix lists 142 websites containing additional information about creating Windows 7 device drivers.

  • + Share This
  • 🔖 Save To Your Account