I am trying to understand how COM specifies the layout of its objects so that a client that wants to use a COM object knows how to do it.
I've read that a COM object that implements multiple interfaces can do it it in different ways including using nested classes or multiple inheritance.
My understanding is that both techniques would have to produce the same memory layout (conforming to the COM spec) so that a client that wants to use the COM object (for example in C), knows how to do it.
So my specific question is: is there a difference in memory layout for c++ objects implemented using multiple inheritance versus nested classes.
And could somebody point me to where a COM object layout is specified?
COM is completely agnostic of the memory layout of your object. All that it wants and needs is a table of function pointers when it calls IUnknown::QueryInterface()
. How you implement it is completely up to you. MFC uses nested classes, just about anything else leverages the built-in support for multiple inheritance in the C++ compiler. The way the MSVC++ compiler implements it is completely compatible with what COM needs. This is no accident. Use the boilerplate code you see listed in books about COM that shows how to properly implement IUnknown.