/*********************************************************************** * GetActiveObject (OLEAUT32.35) * * Gets an object from the global item table. * * PARAMS * rcid [I] CLSID of the object. * preserved [I] Reserved. Set to NULL. * ppunk [O] Address to store object into. * * RETURNS * Success: S_OK. * Failure: HRESULT code. */ HRESULT WINAPI GetActiveObject(REFCLSID rcid,LPVOID preserved,LPUNKNOWN *ppunk) { WCHAR guidbuf[80]; HRESULT ret; LPRUNNINGOBJECTTABLE runobtable; LPMONIKER moniker; StringFromGUID2(rcid,guidbuf,39); ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker); if (FAILED(ret)) return ret; ret = GetRunningObjectTable(0,&runobtable); if (FAILED(ret)) { IMoniker_Release(moniker); return ret; } ret = IRunningObjectTable_GetObject(runobtable,moniker,ppunk); IRunningObjectTable_Release(runobtable); IMoniker_Release(moniker); return ret; }
static HRESULT WINAPI URLMoniker_BindToObject(IMoniker *iface, IBindCtx* pbc, IMoniker *pmkToLeft, REFIID riid, void **ppv) { URLMoniker *This = impl_from_IMoniker(iface); IRunningObjectTable *obj_tbl; HRESULT hres; TRACE("(%p)->(%p,%p,%s,%p)\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppv); hres = IBindCtx_GetRunningObjectTable(pbc, &obj_tbl); if(SUCCEEDED(hres)) { hres = IRunningObjectTable_IsRunning(obj_tbl, &This->IMoniker_iface); if(hres == S_OK) { IUnknown *unk = NULL; TRACE("Found in running object table\n"); hres = IRunningObjectTable_GetObject(obj_tbl, &This->IMoniker_iface, &unk); if(SUCCEEDED(hres)) { hres = IUnknown_QueryInterface(unk, riid, ppv); IUnknown_Release(unk); } IRunningObjectTable_Release(obj_tbl); return hres; } IRunningObjectTable_Release(obj_tbl); } if(!This->uri) { *ppv = NULL; return MK_E_SYNTAX; } return bind_to_object(&This->IMoniker_iface, This->uri, pbc, riid, ppv); }
/****************************************************************************** * FileMoniker_BindToObject */ static HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult) { FileMonikerImpl *This = impl_from_IMoniker(iface); HRESULT res=E_FAIL; CLSID clsID; IUnknown* pObj=0; IRunningObjectTable *prot=0; IPersistFile *ppf=0; IClassFactory *pcf=0; IClassActivator *pca=0; *ppvResult=0; TRACE("(%p,%p,%p,%s,%p)\n",iface,pbc,pmkToLeft,debugstr_guid(riid),ppvResult); if(pmkToLeft==NULL){ res=IBindCtx_GetRunningObjectTable(pbc,&prot); if (SUCCEEDED(res)){ /* if the requested class was loaded before ! we don't need to reload it */ res = IRunningObjectTable_GetObject(prot,iface,&pObj); if (res==S_FALSE){ /* first activation of this class */ res=GetClassFile(This->filePathName,&clsID); if (SUCCEEDED(res)){ res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IPersistFile,(void**)&ppf); if (SUCCEEDED(res)){ res=IPersistFile_Load(ppf,This->filePathName,STGM_READ); if (SUCCEEDED(res)){ pObj=(IUnknown*)ppf; IUnknown_AddRef(pObj); } } } } } } else{ res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassFactory,(void**)&pcf); if (res==E_NOINTERFACE){ res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassActivator,(void**)&pca); if (res==E_NOINTERFACE) return MK_E_INTERMEDIATEINTERFACENOTSUPPORTED; } if (pcf!=NULL){ IClassFactory_CreateInstance(pcf,NULL,&IID_IPersistFile,(void**)&ppf); res=IPersistFile_Load(ppf,This->filePathName,STGM_READ); if (SUCCEEDED(res)){ pObj=(IUnknown*)ppf; IUnknown_AddRef(pObj); } } if (pca!=NULL){ FIXME("()\n"); /*res=GetClassFile(This->filePathName,&clsID); if (SUCCEEDED(res)){ res=IClassActivator_GetClassObject(pca,&clsID,CLSCTX_ALL,0,&IID_IPersistFile,(void**)&ppf); if (SUCCEEDED(res)){ pObj=(IUnknown*)ppf; IUnknown_AddRef(pObj); } }*/ } } if (pObj!=NULL){ /* get the requested interface from the loaded class */ res= IUnknown_QueryInterface(pObj,riid,ppvResult); IBindCtx_RegisterObjectBound(pbc,*ppvResult); IUnknown_Release(pObj); } if (prot!=NULL) IRunningObjectTable_Release(prot); if (ppf!=NULL) IPersistFile_Release(ppf); if (pca!=NULL) IClassActivator_Release(pca); if (pcf!=NULL) IClassFactory_Release(pcf); return res; }