0

I recently came on a quote in Essential com book by Don box

interface ICatDog : ICat, IDog { // illegal, multiple bases

COM prohibits multiple interface inheritance for a variety of reasons. One reason is that the binary representation of the resultant C++ abstract base class would not be compiler invariant

I was wondering if anyone knows why multiple bases is bad for com and would break compiler invariance.

Thank you

2
  • Note that it's only a COM interface that cannot inherit from multiple COM interfaces, in another words, this is fine: class CatDog : ICat, IDog. As for the reason, it's just means the C++ standard (at that time, not sure today) didn't ensure a proper compatibility at binary level with two objects compiled with two different compilers (like MSVC vs GCC for example) Commented Dec 4, 2021 at 7:51
  • The stated reason is fairly nonsensical, any practical COM server written in C++ does in fact rely on MI to implement their interfaces. They just came up with a much better way to do it, one that did not require an extensive specification that dictates the exact v-table layout, gives the implementer lots of flexibility, a way to resolve ambiguity and a backdoor if their C++ compiler is unusual. IUnknown::QueryInterface() was a very good idea. Commented Dec 4, 2021 at 11:44

1 Answer 1

1

Limitation of MIDL tool/COM interface rules.

https://learn.microsoft.com/en-us/windows/win32/com/interface-design-rules

enter image description here

See also:

https://www.codeproject.com/Questions/877467/inheritance-two-ATL-interface

Extending MIDL interfaces and COM object design

https://www.codeproject.com/Articles/1249/A-Multiple-Inheritance-based-COM-Framework

https://www.ooportal.com/basic-com/module2/implementing-com-objects.php

http://computer-programming-forum.com/77-vc-atl/becc8c161a391551.htm

C++ COM design. Composition vs multiple inheritance

https://www.guusbosman.nl/downloads/PaperOop.html

"COM adopted the structure of C++ virtual function tables as the binary representation of an interface. COM interfaces are presented to clients as pointers to virtual tables. This is partly an inheritance from the DLL-technology what Microsoft uses for desktop environments. These allowed multiple client programs to link object implementations at execution time (dynamically)."

COM does not support multiple object inheritance like most object systems. Instead, it relies on inheritance from multiple interfaces for a single object. Each object inherits from IUnknown. The IUnknown interface includes the QueryInterface() method which is used for navigating between the interfaces of an object. In addition the AddRef() and Release() methods are included here. These are used for reference counting and garbage collection. In this way, every server object controls its own lifetime. Each interface has a Globally Unique Identifier (GUID), which must be registered with the Registry. In addition each class also has its own unique class ID (CLSID).

The situation in COM+ is a bit different. According to [Kirtland 97], COM+ will support implementation inheritance, together with object-references (COM doesn’t know object-references, only interface references). However, it is possible to use it, not mandatory. The article says, "it makes versioning a nightmare (see Version control)". In principle, most COM objects will be referred to by interfaces, not with object references.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot for the links, I have gone through some and doing the rest. I am still struggling to understand why new abstract class from multiple interface inheritance is bad and why changes based on compiler, is possible because vtable is different between those and why

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.