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::RuntimeClass<
wrl::RuntimeClassFlags<wrl::ClassicCom>,
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.
I must be missing something. Can the following not achieve the same thing?
namespace wrl = Microsoft::WRL;
struct MyFileSystemBindData :
wrl::RuntimeClass<
wrl::RuntimeClassFlags,
IFileSystemBindData2,
IFileSystemBindData
>
{
⟦ implementation elided for expository purposes ⟧
}
The implementation of IFileSystemBindData2 covers IFileSystemBindData, since the former extends the latter.
If so, why do we need ChainÂInterfaces?
I guess this is the modern version of QITABENTMULTI used with QISearch. That macro was error prone but the generated code is smaller than what templates give you.