about CppWinRT internal 3

108 Views Asked by At

What is the use case of composable_factory? It seems it is related to m_outer, but I can not find any code calling it (Searched all files in the cppwinrt directory). Many thanks!!!

1

There are 1 best solutions below

1
On

composable_factory is used for constructing types that allow inheritance. In the Windows Runtime, since base class and derived classes may be in separate components, or even written in separate languages, they use COM aggregation to stitch the base and derived classes together into what appears to be, to the client, a single object. A good example of this would be if you created your own MyButton class that is not sealed / final. It would both compose with Button and be derivable by other classes.

Much like activation_factory, composable_factory serves as a specialized activation factory for instantiating objects while taking a base class to derive from during construction. You can see how that fits together with the inner & outer args here:

https://github.com/microsoft/cppwinrt/blob/c36cf05f5030726c8ada1b89fc78bd470f737032/strings/base_composable.h

I believe m_outer is typically the base class, and inner is the derived.

Ben