這篇文章給大家介紹接口的實(shí)現(xiàn)以及QueryInterface的實(shí)現(xiàn)和使用方法,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、集寧網(wǎng)絡(luò)推廣、小程序開發(fā)、集寧網(wǎng)絡(luò)營銷、集寧企業(yè)策劃、集寧品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)建站為所有大學(xué)生創(chuàng)業(yè)者提供集寧建站搭建服務(wù),24小時服務(wù)熱線:18980820575,官方網(wǎng)址:www.cdcxhl.com
interface IX : public IUnknown
{
virtual void _stdcall Fx() = 0;
};
interface IY : public IUnknown
{
virtual void _stdcall Fy() = 0;
};
interface IZ : public IUnknown
{
virtual void _stdcall Fz() = 0;
};
static const IID IID_IX = {0xff5ba880, 0xa371, 0x4a42, {0x87, 0x20, 0x96, 0xe0, 0x4d, 0x68, 0xd, 0x76}}; // {FF5BA880-A371-4a42-8720-96E04D680D76}
static const IID IID_IY = {0xde44d538, 0xe926, 0x4d5f, {0x94, 0x5d, 0x61, 0x83, 0x86, 0x7c, 0x63, 0x41}}; // {DE44D538-E926-4d5f-945D-6183867C6341}
static const IID IID_IZ = {0x91157d15, 0x22b1, 0x45d9, {0xb4, 0xc9, 0x81, 0x3, 0x8d, 0xec, 0xef, 0xad}}; // {91157D15-22B1-45d9-B4C9-81038DECEFAD}
class CA : public IX,
public IY
{
public:
virtual HRESULT _stdcall QueryInterface(REFIID riid, __RPC__deref_out void **ppvObject);
virtual ULONG _stdcall AddRef() { return 0; }
virtual ULONG _stdcall Release() { return 0; }
virtual void _stdcall Fx() { cout<<"IX::Fx"< virtual void _stdcall Fy() { cout<<"IY::Fy"< HRESULT _stdcall CA::QueryInterface(REFIID riid, __RPC__deref_out void **ppvObject) reinterpret_cast IUnknown* CreateInstance() void _tmain(int argc,_TCHAR*argv[]) IX *pIX = NULL; IY *pIY = NULL; IZ *pIZ = NULL; IY *pIYFromIX = NULL; IUnknown *pIUnkFromIY = NULL; if(pIUnk) delete pIUnk; 關(guān)于接口的實(shí)現(xiàn)以及QueryInterface的實(shí)現(xiàn)和使用方法就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
{
if(IID_IX == riid)
{
*ppvObject = static_cast
}
else if(IID_IY == riid)
{
*ppvObject = static_cast
}
else if(IID_IUnknown == riid)
{
//*ppvObject = static_cast
*ppvObject = static_cast
}
else
{
*ppvObject = NULL;
return E_NOINTERFACE;
}
return S_OK;
}
{
IUnknown *pIUnk = static_cast
pIUnk->AddRef();
return pIUnk;
}
{
IUnknown *pIUnk = CreateInstance();
HRESULT hr = pIUnk->QueryInterface(IID_IX,(void**)&pIX);
if(SUCCEEDED(hr))
{
pIX->Fx();
}
hr = pIUnk->QueryInterface(IID_IY,(void**)&pIY);
if(SUCCEEDED(hr))
{
pIY->Fy();
}
hr = pIUnk->QueryInterface(IID_IZ,(void**)&pIZ);
if(SUCCEEDED(hr))
{
cout<<"Succeed to find pIZ"<
}
hr = pIX->QueryInterface(IID_IY,(void**)&pIYFromIX);
if(SUCCEEDED(hr))
{
pIYFromIX->Fy();
}
hr = pIY->QueryInterface(IID_IUnknown,(void**)&pIUnkFromIY);
if(SUCCEEDED(hr))
{
if(pIUnkFromIY == pIUnk)
cout<<"pIUnkFromIY == pIUnk"<
cout<<"pIUnkFromIY != pIUnk"<
}
網(wǎng)站欄目:接口的實(shí)現(xiàn)以及QueryInterface的實(shí)現(xiàn)和使用方法
分享路徑:http://weahome.cn/article/igsood.html