When implementing several COM interfaces at once how do I upcast to IUnknown?

后端 未结 4 1255
野性不改
野性不改 2021-01-21 23:43

Suppose my COM object implements two or more COM interfaces:

class CMyClass : public IPersistFile, public IPersistStream {
};

when implementing

4条回答
  •  梦谈多话
    2021-01-22 00:27

    Mark Ransom already gave the correct answer - any will do, as long as it's consistent - but picking the first one has one minor advantage. Due to layout rules, the IUnknown* of the first interface will point to the start of the object. Any other IUnknown* will point to subsequent vtable pointers elsewhere in the object. For debugging purposes, it's very useful to know where ano object begins in memory.

提交回复
热议问题