This page explains interface navigation via IUnknown's QueryInterface method.
IUnknown and Interface Navigation
Previously, we learned that every COM interface implements IUnknown. In this lesson, we will study interface navigation with QueryInterface.
The COM specification states that if a client has an interface pointer into a COM object, it must be able to acquire any other interface implemented within that object. In COM terminology, this is called interface navigation. IUnknown's QueryInterface method supports interface navigation. The following are equivalent prototypes for QueryInterface:
The second form is the one most often used. REFIID is a macro defined to be const IID & and VOID is a "windows" type defined to be void.
Because every COM interface implements QueryInterface, every COM interface supports interface navigation.
The general idea behind implementing QueryInterface is to check the value of the riid parameter against the IIDs of all other interfaces supported by the COM object.
If a match is found, the ppv parameter is assigned the value of the requested interface.
As an example, let us use MyComObject from the previous