首页 > 代码库 > com接口
com接口
1 interface IUnknown 2 { 3 virtual HRESULT __stdcall QueryInterface(const IID & iid, void ** ppv) = 0; 4 virtual ULONG _stdcall AddRef() = 0; 5 virtual ULONG _stdcall Release() = 0; 6 };
1 void foo(IUnknown * pI) 2 { 3 IX * pIX = NULL; 4 HRESULT hr = pI->QueryInterface(IID_IX, (void **)&pIX); 5 if (SUCCEEDED(hr)) 6 { 7 pIX->Fx(); 8 } 9 else 10 ... 11 }
1 HRESULT __stdcall CA::QueryInterface(const IID & iid, void ** ppv) 2 { 3 if (iid == IID_IUnknown) 4 *ppv = static_cast<IUnknown *>this; 5 else if (iid == IID_IX) 6 *ppv = static_cast<IX *>this; 7 else if (iid == IID_IY) 8 *ppv = static_cast<IY *>this; 9 else 10 *ppv = NULL; 11 12 static_cast<IUnknown *>(*ppv)->AddRef(); 13 return S_OK; 14 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。