This is really a COM question, but I'll post it here anyways and hope for the best :)
If a class inherits from IUnknown, then why is it necessary to declare the IUnknown Methods in the inheriting class?
I can understand that if the class was inheriting from some other class that maybe we'd need to add them, but in the vanilla case?

This is for Ultrano:

class Blah, IUnknown, COM compatible
;<----My assumption is that IUnknown Methods are ALREADY HERE
virtual ClassMethod

class Blah, , COM compatible
virtual QueryInterface
virtual AddRef
virtual Release
virtual ClassMethod

class Blah, IUnknown, COM compatible
virtual QueryInterface
virtual AddRef
virtual Release
virtual ClassMethod

In this third example, are we or are we not doubling up on the IUnknown methods? Assuming that I have created an IUnknown Class that contains only the IUnknown methods, it should be enough just to inherit from it, right?
There's no reason for all classes to have their OWN IUnknown really, is there?
I'm just thinking back to something I read on msdn along the lines of "dx classes always derive from IUnknown"...

This may seem like a silly question I have posed, but bear in mind that I am staring at a bunch of C++ class defs, and they use the third style of declaring that they inherit from IUnknown and also (re)defining those Methods each time, which makes it appear as though they are overriding IUnknown for absolutely no reason (just extra call overhead and no benefit).

Anyone else have an opinion please chime in :)
Posted on 2004-04-14 09:39:11 by Homer
I really don't think I can help :)
overriding doesn't add any overhead - the virtual table sits there never changed, and it's hit or miss whether to jump to IUnknown's empty functions, or to Blah's empty functions.
Posted on 2004-04-18 04:36:51 by Ultrano
Thanks anyway.. maybe this will clear things up...
(taken from masm COM folder))
If a COM class contains several interfaces that inherit from IUnknown, EACH INTERFACE should have its own IUnknown methods ???

_vtable STRUCT
DWORD QueryInterface
DWORD Release
DWORD GetTypeInfoCount
DWORD GetTypeInfo
DWORD Invoke_
DWORD put_Value
DWORD get_Value
DWORD put_ForeColor
DWORD get_ForeColor
DWORD put_BackColor
DWORD get_BackColor
DWORD AboutBox
IOleObject DWORD QueryInterface
DWORD Release
DWORD IOleObject_SetClientSite
DWORD IOleObject_GetClientSite
DWORD IOleObject_SetHostNames
DWORD IOleObject_Close
DWORD IOleObject_SetMoniker
DWORD IOleObject_GetMoniker
DWORD IOleObject_InitFromData
DWORD IOleObject_GetClipboardData
DWORD IOleObject_DoVerb
DWORD IOleObject_EnumVerbs
DWORD IOleObject_Update
DWORD IOleObject_IsUpToDate
DWORD IOleObject_GetUserClassID
DWORD IOleObject_GetUserType
DWORD IOleObject_SetExtent
DWORD IOleObject_GetExtent
DWORD IOleObject_Advise
DWORD IOleObject_Unadvise
DWORD IOleObject_EnumAdvise
DWORD IOleObject_GetMiscStatus
DWORD IOleObject_SetColorScheme
IProvideClassInfo DWORD QueryInterface
DWORD Release
DWORD IProvideClassInfo_GetClassInfo
IPersist DWORD QueryInterface
DWORD Release
DWORD IPersist_GetClassID
IPersistStreamInit DWORD QueryInterface
DWORD Release
DWORD IPersist_GetClassID
DWORD IPersistStreamInit_IsDirty
DWORD IPersistStreamInit_Load
DWORD IPersistStreamInit_Save
DWORD IPersistStreamInit_GetSizeMax
DWORD IPersistStreamInit_InitNew

IPersistPropertyBag DWORD QueryInterface
DWORD Release
DWORD IPersist_GetClassID
DWORD IPersistPropertyBag_InitNew
DWORD IPersistPropertyBag_Load
DWORD IPersistPropertyBag_Save

IViewObject DWORD QueryInterface
DWORD Release
DWORD IViewObject_Draw
DWORD IViewObject_GetColorSet
DWORD IViewObject_Freeze
DWORD IViewObject_Unfreeze
DWORD IViewObject_SetAdvise
DWORD IViewObject_GetAdvise
IViewObject2 DWORD IViewObject2_GetExtent
ISpecifyPropertyPages DWORD QueryInterface
DWORD Release
DWORD ISpecifyPropertyPages_GetPages
ICategorizeProperties DWORD QueryInterface
DWORD Release
DWORD ICategorizeProperties_MapPropertyToCategory
DWORD ICategorizeProperties_GetCategoryName
_vtable ENDS

mmmk ... that means that it's simply NOT POSSIBLE to just Inherit Iunknown for the entire class, and furthermore, we have a name collision issue to contend with??? Are the duplicate named entries in this vtable actually pointing to the same or to different versions of the named functions?
Posted on 2004-04-21 02:40:45 by Homer
Each interface represents a different class of objects.

When inheriting, the (virtual function) entries are repeated so that any function from the base class can be found at the same offset for every derived class. Using a different entry value for the derived class is the same as overriding the virtual function.
Posted on 2004-04-21 16:18:47 by tenkey
I think this is the ATC equivalent:

[color=blue]class[/color] IDispatch,IUnknown,COM compatible ; for VB I guess
[color=green]virtual[/color] GetTypeInfoCount
[color=green]virtual[/color] GetTypeInfo
[color=green]virtual[/color] GetIDsOfNames
[color=green]virtual[/color] Invoke_

[color=blue]class[/color] IAsmCtrl,IDispatch,COM compatible ; actually IAsmCtrl is more messy
[color=green]virtual[/color] put_Value
[color=green]virtual[/color] get_Value
[color=green]virtual[/color] Raise
[color=green]virtual[/color] put_ForeColor
[color=green]virtual[/color] get_ForeColor
[color=green]virtual[/color] put_BackColor
[color=green]virtual[/color] get_BackColor
[color=green]virtual[/color] AboutBox
long m_isDirty
long m_advf
long m_pClientSite
long m_pViewAdviseSink
long m_pAdviseHolder
long m_himetricExtent
long m_pixelExtent
long m_Value
long m_BackColor
long m_ForeColor

[color=blue]class[/color] IOleObject,IUnknown,COM compatible
[color=green]virtual[/color] SetClientSite
[color=green]virtual[/color] GetClientSite
[color=green]virtual[/color] SetHostNames
[color=green]virtual[/color] Close
[color=green]virtual[/color] SetMoniker
[color=green]virtual[/color] GetMoniker
[color=green]virtual[/color] InitFromData
[color=green]virtual[/color] GetClipboardData
[color=green]virtual[/color] DoVerb
[color=green]virtual[/color] EnumVerbs
[color=green]virtual[/color] Update
[color=green]virtual[/color] IsUpToDate
[color=green]virtual[/color] GetUserClassID
[color=green]virtual[/color] GetUserType
[color=green]virtual[/color] SetExtent
[color=green]virtual[/color] GetExtent
[color=green]virtual[/color] Advise
[color=green]virtual[/color] Unadvise
[color=green]virtual[/color] EnumAdvise
[color=green]virtual[/color] GetMiscStatus
[color=green]virtual[/color] SetColorScheme

[color=blue]class[/color] IProvideClassInfo,IUnknown,COM compatible
[color=green]virtual[/color] GetClassInfo
[color=blue]class[/color] IPersist,IUnknown,COM compatible
[color=green]virtual[/color] GetClassID
[color=blue]class[/color] IPersistStreamInit,IPersist,COM compatible
[color=green]virtual[/color] IsDirty
[color=green]virtual[/color] Load
[color=green]virtual[/color] Save
[color=green]virtual[/color] GetSizeMax
[color=green]virtual[/color] InitNew
[color=blue]class[/color] IPersistPropertyBag,IPersist,COM compatible
[color=green]virtual[/color] InitNew
[color=green]virtual[/color] Load
[color=green]virtual[/color] Save
[color=blue]class[/color] IViewObject,IUnknown,COM compatible
[color=green]virtual[/color] Draw
[color=green]virtual[/color] GetColorSet
[color=green]virtual[/color] Freeze
[color=green]virtual[/color] unfreeze
[color=green]virtual[/color] SetAdvise
[color=green]virtual[/color] GetAdvise
[color=blue]class[/color] IViewObject2,IViewObject,COM compatible
[color=green]virtual[/color] GetExtent
[color=blue]class[/color] ISpecifyPropertyPages,IUnknown,COM compatible
[color=green]virtual[/color] GetPages
[color=blue]class[/color] ISpecifyPropertyPages,IUnknown,COM compatible
[color=green]virtual[/color] GetPages
[color=blue]class[/color] ICategorizeProperties,IUnknown,COM compatible
[color=green]virtual[/color] MapPropertyToCategory
[color=green]virtual[/color] GetCategoryName
Posted on 2004-04-22 02:40:23 by Ultrano
Thanks very much :)
Posted on 2004-04-22 08:23:36 by Homer