3,245
社区成员
发帖
与我相关
我的任务
分享
void trace(const char* mess){cout<<mess<<endl;}
class CA:public IX,public IY
{
public:
virtual HRESULT _stdcall QueryInterface(const IID& riid, void **ppvObject);
virtual ULONG _stdcall AddRef();
virtual ULONG _stdcall Release();
private:
long m_cRef;
public:
CA():m_cRef(0){}
~CA();
public:
virtual void _stdcall Fx(){cout<<"CA::Fx()"<<endl;}
virtual void _stdcall Fy(){cout<<"CA::Fy()"<<endl;}
};
CA::~CA()
{
trace("CA:Release himself");
}
HRESULT _stdcall CA::QueryInterface(const IID& riid, void **ppvObject)
{
if(riid==IID_IUnknown)
{
trace("client get the interface IUnkown");
*ppvObject=static_cast<IX*>(this);
}
else if(riid==IID_IX)
{
trace("client get the interface IX.");
*ppvObject=static_cast<IX*>(this);
}
else if (riid==IID_IY)
{
trace("client get the interface IY");
*ppvObject=static_cast<IY*>(this);
}
else if (riid==IID_IZ)
{
trace("client can not get the interface IZ");
*ppvObject=NULL;
return E_NOINTERFACE;
}
else
{
trace("the component do not support this interface");
*ppvObject=NULL;
return E_NOINTERFACE;
}
reinterpret_cast<IX*>(this)->AddRef();
return S_OK;
}
ULONG _stdcall CA::AddRef()
{
trace("CA:QA add ref count");
return ::InterlockedIncrement(&m_cRef);
}
ULONG _stdcall CA::Release()
{
trace("CA:QA substract ref count");
if(InterlockedDecrement(&m_cRef)==0)
{
delete this;
return 0;
}
return m_cRef;
}
http://download.csdn.net/source/1401481