COM聚合时候对IUnknown有两个不同的实现

gooore 2010-02-25 11:45:36
COM聚合的时候对IUnknown有两个不同的实现,请教书上的这段话该怎么用vtbl来理解?

You might expect that with two implementations of IUnknown in one object, naming collisions would occur. You can avoid this problem by giving the second implementation of IUnknown a new name: INoAggregationUnknown. Because COM+ is a binary standard, it is not concerned with the name given to an interface—only with its v-table layout. Therefore, the INoAggregationUnknown interface is defined with a v-table structure identical to that of the real IUnknown:

interface INoAggregationUnknown
{
virtual HRESULT __stdcall QueryInterface_NoAggregation(
REFIID riid, void** ppv)=0;
virtual ULONG __stdcall AddRef_NoAggregation()=0;
virtual ULONG __stdcall Release_NoAggregation()=0;
};
...全文
88 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gooore 2010-02-27
  • 打赏
  • 举报
回复
http://blog.csdn.net/nobugtodebug/archive/2009/10/12/4659351.aspx

好文章,看完弄懂了,希望也能帮到有类似问题的朋友。
gooore 2010-02-26
  • 打赏
  • 举报
回复

不理解,主要是下面的代码中m_pUnknownInner->QueryInterface(riid, ppv);会调用
QueryInterface_NoAggregation(REFIID riid, void** ppv),系统是怎么知道该运行这个函数的?


HRESULT CAggregator::QueryInterface(REFIID riid, void** ppv)
{
if(riid == IID_IUnknown)
{
cout << "Container: CAggregator::QueryInterface() for IUnknown returning " << this << endl;
*ppv = (IUnknown*)this;
}
else if(riid == IID_ISum)
{
cout << "Container: CAggregator::QueryInterface() for ISum calling inside object" << endl;
return m_pUnknownInner->QueryInterface(riid, ppv);
}
else if(riid == IID_IMultiply)
{
cout << "Container: CAggregator::QueryInterface() for ISum returning " << this << endl;
*ppv = (IMultiply*)this;
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
jameshooo 2010-02-25
  • 打赏
  • 举报
回复
虚表只有一个,但三个方法要实现两套,换个名称即可,例如 Outer_QueryInterface/Outer_AddRef/Outer_Release,原始的那套方法要判断自己是不是被聚合了,选择性把调用转移到第二套方法里。

3,248

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧