1

Seems like both COM_INTERFACE_ENTRY_IID and COM_INTERFACE_ENTRY2_IID are for the case when the class is derived from two or more classes each derived from a common interface. Like this:

class CMyClass : public IPersistFile, public IPersistStream { 

};

(both IPersistStream and IPersistFile derive from IPersist).

Looks like I'm free to include either

COM_INTERFACE_ENTRY_IID( __uuidof( IPersist ), IPersistFile )

or

COM_INTERFACE_ENTRY2_IID( __uuidof( IPersist ), IPersist, IPersistFile )

into the COM map of my class and it will work allright.

Is there any difference between the two?

4

1 回答 1

2

根据ATL Internals(根据您在这里的问题,您绝对应该得到的一本书——其中大部分都被彻底涵盖了!),两者基本上是等价的。

  • COM_INTERFACE_ENTRY 仅提及接口名称,并将其 IID 映射到 vtable 偏移量
  • COM_INTERFACE_ENTRY2 提到了接口名称以及继承树中的哪个分支用于 vtable 偏移
  • COM_INTERFACE_ENTRY_IID 将 IID 映射到接口,从而允许您选择继承树分支
  • COM_INTERFACE_ENTRY2_IID 做这一切;将 IID 映射到接口,并明确继承树分支

ATL Internals 的作者说:

由于 COM_INTERFACE_ENTRY2[_IID] 没有提供超出 COM_INTERFACE_ENTRY[_IID] 提供的额外功能,因此我倾向于总是使用后者而忘记前者。

我认为他们的意思是,如果您使用 COM_INTERFACE_ENTRY_IID,则您已经选择了分支,因此 COM_INTERFACE_ENTRY2[_IID] 系列不会添加任何内容。但是 COM_INTERFACE_ENTRY2 使用 COM_INTERFACE_ENTRY_IID 稍微简单一些。

于 2009-11-17T14:04:16.510 回答