static HRESULT WINAPI IHlinkBC_Register(IHlinkBrowseContext* iface, DWORD dwReserved, IUnknown *piunk, IMoniker *pimk, DWORD *pdwRegister) { static const WCHAR szIdent[] = {'W','I','N','E','H','L','I','N','K',0}; HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface); IMoniker *mon; IMoniker *composite; IRunningObjectTable *ROT; HRESULT hr; FIXME("(%p)->(%i %p %p %p)\n", This, dwReserved, piunk, pimk, pdwRegister); hr = CreateItemMoniker(NULL, szIdent, &mon); if (FAILED(hr)) return hr; CreateGenericComposite(mon, pimk, &composite); GetRunningObjectTable(0, &ROT); IRunningObjectTable_Register(ROT, 0, piunk, composite, pdwRegister); IRunningObjectTable_Release(ROT); IMoniker_Release(composite); IMoniker_Release(mon); return S_OK; }
/*********************************************************************** * RegisterActiveObject (OLEAUT32.33) * * Registers an object in the global item table. * * PARAMS * punk [I] Object to register. * rcid [I] CLSID of the object. * dwFlags [I] Flags. * pdwRegister [O] Address to store cookie of object registration in. * * RETURNS * Success: S_OK. * Failure: HRESULT code. */ HRESULT WINAPI RegisterActiveObject( LPUNKNOWN punk,REFCLSID rcid,DWORD dwFlags,LPDWORD pdwRegister ) { WCHAR guidbuf[80]; HRESULT ret; LPRUNNINGOBJECTTABLE runobtable; LPMONIKER moniker; DWORD rot_flags = ROTFLAGS_REGISTRATIONKEEPSALIVE; /* default registration is strong */ 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; } if(dwFlags == ACTIVEOBJECT_WEAK) rot_flags = 0; ret = IRunningObjectTable_Register(runobtable,rot_flags,punk,moniker,pdwRegister); IRunningObjectTable_Release(runobtable); IMoniker_Release(moniker); return ret; }
/****************************************************************************** * FileMoniker_IsRunning */ static HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning) { IRunningObjectTable* rot; HRESULT res; TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning); if ( (pmkNewlyRunning!=NULL) && (IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK) ) return S_OK; if (pbc==NULL) return E_POINTER; res=IBindCtx_GetRunningObjectTable(pbc,&rot); if (FAILED(res)) return res; res = IRunningObjectTable_IsRunning(rot,iface); IRunningObjectTable_Release(rot); return res; }
static NTSTATUS EnumRunningObjectTable( _In_ PVOID ThreadParam ) { IRunningObjectTable* iRunningObjectTable = NULL; IEnumMoniker* iEnumMoniker = NULL; IMoniker* iMoniker = NULL; IBindCtx* iBindCtx = NULL; IMalloc* iMalloc = NULL; ULONG count = 0; HWND listViewHandle = (HWND)ThreadParam; if (!SUCCEEDED(CoGetMalloc(1, &iMalloc))) return STATUS_INSUFFICIENT_RESOURCES; // Query the running object table address if (SUCCEEDED(GetRunningObjectTable(0, &iRunningObjectTable))) { // Enum the objects registered if (SUCCEEDED(IRunningObjectTable_EnumRunning(iRunningObjectTable, &iEnumMoniker))) { while (IEnumMoniker_Next(iEnumMoniker, 1, &iMoniker, &count) == S_OK) { if (SUCCEEDED(CreateBindCtx(0, &iBindCtx))) { OLECHAR* displayName = NULL; // Query the object name if (SUCCEEDED(IMoniker_GetDisplayName(iMoniker, iBindCtx, NULL, &displayName))) { // Set the items name column PhAddListViewItem(listViewHandle, MAXINT, displayName, NULL); // Free the object name IMalloc_Free(iMalloc, displayName); } IBindCtx_Release(iBindCtx); } IEnumMoniker_Release(iMoniker); } IEnumMoniker_Release(iEnumMoniker); } IRunningObjectTable_Release(iRunningObjectTable); } IMalloc_Release(iMalloc); return STATUS_SUCCESS; }
/*********************************************************************** * RevokeActiveObject (OLEAUT32.34) * * Revokes an object from the global item table. * * PARAMS * xregister [I] Registration cookie. * reserved [I] Reserved. Set to NULL. * * RETURNS * Success: S_OK. * Failure: HRESULT code. */ HRESULT WINAPI RevokeActiveObject(DWORD xregister,LPVOID reserved) { LPRUNNINGOBJECTTABLE runobtable; HRESULT ret; ret = GetRunningObjectTable(0,&runobtable); if (FAILED(ret)) return ret; ret = IRunningObjectTable_Revoke(runobtable,xregister); if (SUCCEEDED(ret)) ret = S_OK; IRunningObjectTable_Release(runobtable); 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); }
static HRESULT WINAPI IHlinkBC_Revoke(IHlinkBrowseContext* iface, DWORD dwRegister) { HRESULT r = S_OK; IRunningObjectTable *ROT; HlinkBCImpl *This = (HlinkBCImpl*)iface; FIXME("(%p)->(%li)\n", This, dwRegister); GetRunningObjectTable(0, &ROT); r = IRunningObjectTable_Revoke(ROT, dwRegister); IRunningObjectTable_Release(ROT); return r; }
/****************************************************************************** * ItemMoniker_IsRunning ******************************************************************************/ static HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning) { ItemMonikerImpl *This = impl_from_IMoniker(iface); IRunningObjectTable* rot; HRESULT res; IOleItemContainer *poic=0; TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning); /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */ /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */ if (pmkToLeft==NULL) if ((pmkNewlyRunning!=NULL)&&(IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK)) return S_OK; else { if (pbc==NULL) return E_INVALIDARG; res=IBindCtx_GetRunningObjectTable(pbc,&rot); if (FAILED(res)) return res; res = IRunningObjectTable_IsRunning(rot,iface); IRunningObjectTable_Release(rot); } else{ /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */ /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/ /* passing the string contained within this moniker. */ res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic); if (SUCCEEDED(res)){ res=IOleItemContainer_IsRunning(poic,This->itemName); IOleItemContainer_Release(poic); } } return res; }
/****************************************************************************** * URLMoniker_BindToObject ******************************************************************************/ static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppv) { URLMonikerImpl *This = (URLMonikerImpl *)iface; IRunningObjectTable *obj_tbl; HRESULT hres; TRACE("(%p)->(%p,%p,%s,%p): stub\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppv); hres = IBindCtx_GetRunningObjectTable(pbc, &obj_tbl); if(SUCCEEDED(hres)) { FIXME("use running object table\n"); IRunningObjectTable_Release(obj_tbl); } return bind_to_object(iface, This->URLName, pbc, riid, ppv); }
/*********************************************************************** * 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)) { FIXME("use running object table\n"); 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); }
/*********************************************************************** * RegisterActiveObject (OLEAUT32.33) * * Registers an object in the global item table. * * PARAMS * punk [I] Object to register. * rcid [I] CLSID of the object. * dwFlags [I] Flags. * pdwRegister [O] Address to store cookie of object registration in. * * RETURNS * Success: S_OK. * Failure: HRESULT code. */ HRESULT WINAPI RegisterActiveObject( LPUNKNOWN punk,REFCLSID rcid,DWORD dwFlags,LPDWORD pdwRegister ) { 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_Register(runobtable,dwFlags,punk,moniker,pdwRegister); IRunningObjectTable_Release(runobtable); IMoniker_Release(moniker); return ret; }
/****************************************************************************** * AntiMoniker_IsRunning ******************************************************************************/ static HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning) { IRunningObjectTable* rot; HRESULT res; TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning); if (pbc==NULL) return E_INVALIDARG; res=IBindCtx_GetRunningObjectTable(pbc,&rot); if (FAILED(res)) return res; res = IRunningObjectTable_IsRunning(rot,iface); IRunningObjectTable_Release(rot); return res; }
/****************************************************************************** * 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; }
HRESULT FileMoniker_CreateFromDisplayName(LPBC pbc, LPCOLESTR szDisplayName, LPDWORD pchEaten, IMoniker **ppmk) { LPCWSTR end; static const WCHAR wszSeparators[] = {':','\\','/','!',0}; for (end = szDisplayName + strlenW(szDisplayName); end && (end != szDisplayName); end = memrpbrkW(szDisplayName, end - szDisplayName, wszSeparators)) { HRESULT hr; IRunningObjectTable *rot; IMoniker *file_moniker; LPWSTR file_display_name; LPWSTR full_path_name; DWORD full_path_name_len; int len = end - szDisplayName; file_display_name = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR)); if (!file_display_name) return E_OUTOFMEMORY; memcpy(file_display_name, szDisplayName, len * sizeof(WCHAR)); file_display_name[len] = '\0'; hr = CreateFileMoniker(file_display_name, &file_moniker); if (FAILED(hr)) { HeapFree(GetProcessHeap(), 0, file_display_name); return hr; } hr = IBindCtx_GetRunningObjectTable(pbc, &rot); if (FAILED(hr)) { HeapFree(GetProcessHeap(), 0, file_display_name); IMoniker_Release(file_moniker); return hr; } hr = IRunningObjectTable_IsRunning(rot, file_moniker); IRunningObjectTable_Release(rot); if (FAILED(hr)) { HeapFree(GetProcessHeap(), 0, file_display_name); IMoniker_Release(file_moniker); return hr; } if (hr == S_OK) { TRACE("found running file moniker for %s\n", debugstr_w(file_display_name)); *pchEaten = len; *ppmk = file_moniker; HeapFree(GetProcessHeap(), 0, file_display_name); return S_OK; } full_path_name_len = GetFullPathNameW(file_display_name, 0, NULL, NULL); if (!full_path_name_len) { HeapFree(GetProcessHeap(), 0, file_display_name); IMoniker_Release(file_moniker); return MK_E_SYNTAX; } full_path_name = HeapAlloc(GetProcessHeap(), 0, full_path_name_len * sizeof(WCHAR)); if (!full_path_name) { HeapFree(GetProcessHeap(), 0, file_display_name); IMoniker_Release(file_moniker); return E_OUTOFMEMORY; } GetFullPathNameW(file_display_name, full_path_name_len, full_path_name, NULL); if (GetFileAttributesW(full_path_name) == INVALID_FILE_ATTRIBUTES) TRACE("couldn't open file %s\n", debugstr_w(full_path_name)); else { TRACE("got file moniker for %s\n", debugstr_w(szDisplayName)); *pchEaten = len; *ppmk = file_moniker; HeapFree(GetProcessHeap(), 0, file_display_name); HeapFree(GetProcessHeap(), 0, full_path_name); return S_OK; } HeapFree(GetProcessHeap(), 0, file_display_name); HeapFree(GetProcessHeap(), 0, full_path_name); IMoniker_Release(file_moniker); } return MK_E_CANTOPENFILE; }