包容:外部对象的实现 CBH CBO m_psomeInterface= NULLI I Ref= Or CBHNCB( if(m-pSomeInterface NULL m_psomeInterface->Released HRESULT CB: InitO HRESULT result = CoCreateInstance(CLSID_ComponentA, NULL CLSCTX_ INPROC_ SERVER, IID_ISomeInterface (void *x)&m_-pSomeInterface)i if(FAILED(result)) return E_FAIL els return S_OK包容:外部对象的实现 包容:外部对象的实现 CB::CB ( ) CB::CB ( ) { m_pSomeInterface pSomeInterface = NULL; = NULL; m_Ref = 0; m_Ref = 0; } CB::~CB ( ) CB::~CB ( ) { if (m_pSomeInterface pSomeInterface ! = NULL) ! = NULL) m_pSomeInterface pSomeInterface->Release() ; ->Release() ; } HRESULT HRESULT CB::Init() CB::Init() { HRESULT result = :: HRESULT result = ::CoCreateInstance CoCreateInstance(CLSID_ (CLSID_ComponentA, NULL, , NULL, CLSCTX_INPROC_SERVER, IID_ CLSCTX_INPROC_SERVER, IID_ISomeInterface ISomeInterface, (void **)&m_ (void **)&m_pSomeInterface pSomeInterface) ; if (FAILED(result)) if (FAILED(result)) return E_FAIL; return E_FAIL; else return S_OK; return S_OK; }