Should the IUnknown interface be reimplemented by each new COM class?

Sorry if this question seems obvious to everyone, but I'm very new to COM. From the tutorial that I see here http://www.codeguru.com/cpp/com-tech/activex/tutorials/article.php/c5567 , it seems that every COM class created in C ++ should implement its own QueryInterface , AddRef and Release. Since these methods should basically have the same implementation for any new class, I don’t understand why there is no abstract class or anything else that implements it for the developer. I don’t understand why I should repeat the same thing that many people have already implemented over and over again (unless the lesson is wrong and there is something).

thanks

+4
source share
3 answers

FTA:

"I believe that every programmer who wants to understand the basic principles of COM should write at least one simple COM object using simple C ++, that is, without the help of the templates and macros that come with MFC / ATL."

To answer your question: Yes, each COM component must implement the IUnknown , on which the COM module is based. However, as for the "standard pluming" for creating COM objects, this is what the ATL Project Wizard is for.

+3
source

If you don't want to use ATL or other helper libraries, you can use the helper function QISearch , which handles the QueryInterface for you. AddRef and Release can be implemented in your base class.

COM should work with regular C, so sdk windows really do not go beyond the definition of a class and its methods.

+1
source

Yes, every COM class must implement IUnknown , because every COM class inherits from IUnknown - one of the main principles of COM technology. This is usually done using ATL - it has templates and macros for this rather easily, and even if you do not want to use ATL, you can easily write a template for most trivial cases (for example, implement one interface) and reuse it.

+1
source

All Articles