A quick note about WRL’s Chain­Interfaces template class

Raymond Chen

The Windows Runtime C++ Template Library (commonly known as WRL) contains a template class called Chain­Interfaces. The documentation for Chain­Interfaces talks about what it does but doesn’t tell you why it’s there or when you should use it.

The purpose of Chain­Interfaces is to be included among the template arguments to the WRL Runtime­Class and Implements template classes to indicate that you have a sequence (“chain”) of interfaces where each one extends the previous one.

For example, the IFileSystemBindData2 interface extends the IFileSystemBindData interface. If you want to use WRL to implement an object that implements both interfaces, you would write

namespace wrl = Microsoft::WRL;

struct MyFileSystemBindData :
        wrl::ChainInterfaces<IFileSystemBindData2, IFileSystemBindData>
    ⟦ implementation elided for expository purposes ⟧

Note that you list the Chain­Interfaces template parameters from most derived to least derived. Fortunately, if you get the order wrong, you get a compile-time error.