1 /***************************************************************************************
2 * ItemMonikers implementation
4 * Copyright 1999 Noomen Hamza
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ***************************************************************************************/
26 #include "wine/debug.h"
28 #include "wine/unicode.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(ole);
32 /* ItemMoniker data structure */
33 typedef struct ItemMonikerImpl{
35 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
37 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
38 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
40 ICOM_VTABLE(IROTData)* lpvtbl2; /* VTable relative to the IROTData interface.*/
42 ULONG ref; /* reference counter for this object */
44 LPOLESTR itemName; /* item name identified by this ItemMoniker */
46 LPOLESTR itemDelimiter; /* Delimiter string */
50 /********************************************************************************/
51 /* ItemMoniker prototype functions : */
53 /* IUnknown prototype functions */
54 static HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
55 static ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface);
56 static ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface);
58 /* IPersist prototype functions */
59 static HRESULT WINAPI ItemMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
61 /* IPersistStream prototype functions */
62 static HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface);
63 static HRESULT WINAPI ItemMonikerImpl_Load(IMoniker* iface, IStream* pStm);
64 static HRESULT WINAPI ItemMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
65 static HRESULT WINAPI ItemMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
67 /* IMoniker prototype functions */
68 static HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
69 static HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
70 static HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
71 static HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
72 static HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
73 static HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
74 static HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
75 static HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
76 static HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pItemTime);
77 static HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
78 static HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
79 static HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
80 static HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
81 static HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
82 static HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
84 /* Local function used by ItemMoniker implementation */
85 HRESULT WINAPI ItemMonikerImpl_Construct(ItemMonikerImpl* iface, LPCOLESTR lpszDelim,LPCOLESTR lpszPathName);
86 HRESULT WINAPI ItemMonikerImpl_Destroy(ItemMonikerImpl* iface);
88 /********************************************************************************/
89 /* IROTData prototype functions */
91 /* IUnknown prototype functions */
92 static HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
93 static ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData* iface);
94 static ULONG WINAPI ItemMonikerROTDataImpl_Release(IROTData* iface);
96 /* IROTData prototype function */
97 static HRESULT WINAPI ItemMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
99 /********************************************************************************/
100 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
101 /* IPersistStream and IMoniker functions. */
102 static ICOM_VTABLE(IMoniker) VT_ItemMonikerImpl =
104 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
105 ItemMonikerImpl_QueryInterface,
106 ItemMonikerImpl_AddRef,
107 ItemMonikerImpl_Release,
108 ItemMonikerImpl_GetClassID,
109 ItemMonikerImpl_IsDirty,
110 ItemMonikerImpl_Load,
111 ItemMonikerImpl_Save,
112 ItemMonikerImpl_GetSizeMax,
113 ItemMonikerImpl_BindToObject,
114 ItemMonikerImpl_BindToStorage,
115 ItemMonikerImpl_Reduce,
116 ItemMonikerImpl_ComposeWith,
117 ItemMonikerImpl_Enum,
118 ItemMonikerImpl_IsEqual,
119 ItemMonikerImpl_Hash,
120 ItemMonikerImpl_IsRunning,
121 ItemMonikerImpl_GetTimeOfLastChange,
122 ItemMonikerImpl_Inverse,
123 ItemMonikerImpl_CommonPrefixWith,
124 ItemMonikerImpl_RelativePathTo,
125 ItemMonikerImpl_GetDisplayName,
126 ItemMonikerImpl_ParseDisplayName,
127 ItemMonikerImpl_IsSystemMoniker
130 /********************************************************************************/
131 /* Virtual function table for the IROTData class. */
132 static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
134 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
135 ItemMonikerROTDataImpl_QueryInterface,
136 ItemMonikerROTDataImpl_AddRef,
137 ItemMonikerROTDataImpl_Release,
138 ItemMonikerROTDataImpl_GetComparaisonData
141 /*******************************************************************************
142 * ItemMoniker_QueryInterface
143 *******************************************************************************/
144 HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
146 ICOM_THIS(ItemMonikerImpl,iface);
148 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
150 /* Perform a sanity check on the parameters.*/
151 if ( (This==0) || (ppvObject==0) )
154 /* Initialize the return parameter */
157 /* Compare the riid with the interface IDs implemented by this object.*/
158 if (IsEqualIID(&IID_IUnknown, riid) ||
159 IsEqualIID(&IID_IPersist, riid) ||
160 IsEqualIID(&IID_IPersistStream, riid) ||
161 IsEqualIID(&IID_IMoniker, riid)
165 else if (IsEqualIID(&IID_IROTData, riid))
166 *ppvObject = (IROTData*)&(This->lpvtbl2);
168 /* Check that we obtained an interface.*/
170 return E_NOINTERFACE;
172 /* Query Interface always increases the reference count by one when it is successful */
173 ItemMonikerImpl_AddRef(iface);
178 /******************************************************************************
180 ******************************************************************************/
181 ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface)
183 ICOM_THIS(ItemMonikerImpl,iface);
185 TRACE("(%p)\n",This);
187 return ++(This->ref);
190 /******************************************************************************
191 * ItemMoniker_Release
192 ******************************************************************************/
193 ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface)
195 ICOM_THIS(ItemMonikerImpl,iface);
197 TRACE("(%p)\n",This);
201 /* destroy the object if there's no more reference on it */
204 ItemMonikerImpl_Destroy(This);
211 /******************************************************************************
212 * ItemMoniker_GetClassID
213 ******************************************************************************/
214 HRESULT WINAPI ItemMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
216 TRACE("(%p,%p),stub!\n",iface,pClassID);
221 *pClassID = CLSID_ItemMoniker;
226 /******************************************************************************
227 * ItemMoniker_IsDirty
228 ******************************************************************************/
229 HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface)
231 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
232 method in the OLE-provided moniker interfaces always return S_FALSE because
233 their internal state never changes. */
235 TRACE("(%p)\n",iface);
240 /******************************************************************************
242 ******************************************************************************/
243 HRESULT WINAPI ItemMonikerImpl_Load(IMoniker* iface,IStream* pStm)
246 ICOM_THIS(ItemMonikerImpl,iface);
248 DWORD delimiterLength,nameLength,lenW;
249 CHAR *itemNameA,*itemDelimiterA;
252 /* for more details about data read by this function see coments of ItemMonikerImpl_Save function */
254 /* read item delimiter string length + 1 */
255 res=IStream_Read(pStm,&delimiterLength,sizeof(DWORD),&bread);
256 if (bread != sizeof(DWORD))
259 /* read item delimiter string */
260 if (!(itemDelimiterA=HeapAlloc(GetProcessHeap(),0,delimiterLength)))
261 return E_OUTOFMEMORY;
262 res=IStream_Read(pStm,itemDelimiterA,delimiterLength,&bread);
263 if (bread != delimiterLength)
265 HeapFree( GetProcessHeap(), 0, itemDelimiterA );
269 lenW = MultiByteToWideChar( CP_ACP, 0, itemDelimiterA, -1, NULL, 0 );
270 This->itemDelimiter=HeapReAlloc(GetProcessHeap(),0,This->itemDelimiter,lenW*sizeof(WCHAR));
271 if (!This->itemDelimiter)
273 HeapFree( GetProcessHeap(), 0, itemDelimiterA );
274 return E_OUTOFMEMORY;
276 MultiByteToWideChar( CP_ACP, 0, itemDelimiterA, -1, This->itemDelimiter, lenW );
277 HeapFree( GetProcessHeap(), 0, itemDelimiterA );
279 /* read item name string length + 1*/
280 res=IStream_Read(pStm,&nameLength,sizeof(DWORD),&bread);
281 if (bread != sizeof(DWORD))
284 /* read item name string */
285 if (!(itemNameA=HeapAlloc(GetProcessHeap(),0,nameLength)))
286 return E_OUTOFMEMORY;
287 res=IStream_Read(pStm,itemNameA,nameLength,&bread);
288 if (bread != nameLength)
290 HeapFree( GetProcessHeap(), 0, itemNameA );
294 lenW = MultiByteToWideChar( CP_ACP, 0, itemNameA, -1, NULL, 0 );
295 This->itemName=HeapReAlloc(GetProcessHeap(),0,This->itemName,lenW*sizeof(WCHAR));
298 HeapFree( GetProcessHeap(), 0, itemNameA );
299 return E_OUTOFMEMORY;
301 MultiByteToWideChar( CP_ACP, 0, itemNameA, -1, This->itemName, lenW );
302 HeapFree( GetProcessHeap(), 0, itemNameA );
307 /******************************************************************************
309 ******************************************************************************/
310 HRESULT WINAPI ItemMonikerImpl_Save(IMoniker* iface,
311 IStream* pStm,/* pointer to the stream where the object is to be saved */
312 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
314 ICOM_THIS(ItemMonikerImpl,iface);
316 CHAR *itemNameA,*itemDelimiterA;
318 /* data writen by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
319 /* 2) String (type A): item delimiter string ('\0' included) */
320 /* 3) DWORD : size of item name string ('\0' included) */
321 /* 4) String (type A): item name string ('\0' included) */
323 DWORD nameLength = WideCharToMultiByte( CP_ACP, 0, This->itemName, -1, NULL, 0, NULL, NULL);
324 DWORD delimiterLength = WideCharToMultiByte( CP_ACP, 0, This->itemDelimiter, -1, NULL, 0, NULL, NULL);
325 itemNameA=HeapAlloc(GetProcessHeap(),0,nameLength);
326 itemDelimiterA=HeapAlloc(GetProcessHeap(),0,delimiterLength);
327 WideCharToMultiByte( CP_ACP, 0, This->itemName, -1, itemNameA, nameLength, NULL, NULL);
328 WideCharToMultiByte( CP_ACP, 0, This->itemDelimiter, -1, itemDelimiterA, delimiterLength, NULL, NULL);
330 res=IStream_Write(pStm,&delimiterLength,sizeof(DWORD),NULL);
331 res=IStream_Write(pStm,itemDelimiterA,delimiterLength * sizeof(CHAR),NULL);
332 res=IStream_Write(pStm,&nameLength,sizeof(DWORD),NULL);
333 res=IStream_Write(pStm,itemNameA,nameLength * sizeof(CHAR),NULL);
338 /******************************************************************************
339 * ItemMoniker_GetSizeMax
340 ******************************************************************************/
341 HRESULT WINAPI ItemMonikerImpl_GetSizeMax(IMoniker* iface,
342 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
344 ICOM_THIS(ItemMonikerImpl,iface);
345 DWORD delimiterLength=lstrlenW(This->itemDelimiter)+1;
346 DWORD nameLength=lstrlenW(This->itemName)+1;
348 TRACE("(%p,%p)\n",iface,pcbSize);
353 /* for more details see ItemMonikerImpl_Save coments */
355 pcbSize->s.LowPart = sizeof(DWORD) + /* DWORD which contains delimiter length */
356 delimiterLength + /* item delimiter string */
357 sizeof(DWORD) + /* DWORD which contains item name length */
358 nameLength + /* item name string */
359 34; /* this constant was added ! because when I tested this function it usually */
360 /* returns 34 bytes more than the number of bytes used by IMoniker::Save function */
361 pcbSize->s.HighPart=0;
366 /******************************************************************************
367 * ItemMoniker_Construct (local function)
368 *******************************************************************************/
369 HRESULT WINAPI ItemMonikerImpl_Construct(ItemMonikerImpl* This, LPCOLESTR lpszDelim,LPCOLESTR lpszItem)
372 int sizeStr1=lstrlenW(lpszItem), sizeStr2;
373 static const OLECHAR emptystr[1];
376 TRACE("(%p,%p)\n",This,lpszItem);
378 /* Initialize the virtual fgunction table. */
379 This->lpvtbl1 = &VT_ItemMonikerImpl;
380 This->lpvtbl2 = &VT_ROTDataImpl;
383 This->itemName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr1+1));
385 return E_OUTOFMEMORY;
386 lstrcpyW(This->itemName,lpszItem);
389 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
391 delim = lpszDelim ? lpszDelim : emptystr;
393 sizeStr2=lstrlenW(delim);
394 This->itemDelimiter=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr2+1));
395 if (!This->itemDelimiter) {
396 HeapFree(GetProcessHeap(),0,This->itemName);
397 return E_OUTOFMEMORY;
399 lstrcpyW(This->itemDelimiter,delim);
403 /******************************************************************************
404 * ItemMoniker_Destroy (local function)
405 *******************************************************************************/
406 HRESULT WINAPI ItemMonikerImpl_Destroy(ItemMonikerImpl* This)
408 TRACE("(%p)\n",This);
411 HeapFree(GetProcessHeap(),0,This->itemName);
413 if (This->itemDelimiter)
414 HeapFree(GetProcessHeap(),0,This->itemDelimiter);
416 HeapFree(GetProcessHeap(),0,This);
421 /******************************************************************************
422 * ItemMoniker_BindToObject
423 ******************************************************************************/
424 HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface,
430 ICOM_THIS(ItemMonikerImpl,iface);
433 IID refid=IID_IOleItemContainer;
434 IOleItemContainer *poic=0;
436 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
446 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&refid,(void**)&poic);
450 res=IOleItemContainer_GetObject(poic,This->itemName,BINDSPEED_MODERATE,pbc,riid,ppvResult);
452 IOleItemContainer_Release(poic);
458 /******************************************************************************
459 * ItemMoniker_BindToStorage
460 ******************************************************************************/
461 HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker* iface,
467 ICOM_THIS(ItemMonikerImpl,iface);
470 IOleItemContainer *poic=0;
472 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
479 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic);
483 res=IOleItemContainer_GetObjectStorage(poic,This->itemName,pbc,riid,ppvResult);
485 IOleItemContainer_Release(poic);
491 /******************************************************************************
493 ******************************************************************************/
494 HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface,
496 DWORD dwReduceHowFar,
497 IMoniker** ppmkToLeft,
498 IMoniker** ppmkReduced)
500 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
502 if (ppmkReduced==NULL)
505 ItemMonikerImpl_AddRef(iface);
509 return MK_S_REDUCED_TO_SELF;
511 /******************************************************************************
512 * ItemMoniker_ComposeWith
513 ******************************************************************************/
514 HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface,
516 BOOL fOnlyIfNotGeneric,
517 IMoniker** ppmkComposite)
521 IEnumMoniker* penumMk=0;
522 IMoniker *pmostLeftMk=0;
523 IMoniker* tempMkComposite=0;
525 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
527 if ((ppmkComposite==NULL)||(pmkRight==NULL))
532 IMoniker_IsSystemMoniker(pmkRight,&mkSys);
534 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
535 if(mkSys==MKSYS_ANTIMONIKER)
539 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
540 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
542 if(mkSys==MKSYS_GENERICCOMPOSITE){
544 res=IMoniker_Enum(pmkRight,TRUE,&penumMk);
549 res=IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL);
551 IMoniker_IsSystemMoniker(pmostLeftMk,&mkSys2);
553 if(mkSys2==MKSYS_ANTIMONIKER){
555 IMoniker_Release(pmostLeftMk);
557 tempMkComposite=iface;
558 IMoniker_AddRef(iface);
560 while(IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL)==S_OK){
562 res=CreateGenericComposite(tempMkComposite,pmostLeftMk,ppmkComposite);
564 IMoniker_Release(tempMkComposite);
565 IMoniker_Release(pmostLeftMk);
567 tempMkComposite=*ppmkComposite;
568 IMoniker_AddRef(tempMkComposite);
573 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
575 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
576 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
577 a NULL moniker and a return value of MK_E_NEEDGENERIC */
579 if (!fOnlyIfNotGeneric)
580 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
583 return MK_E_NEEDGENERIC;
586 /******************************************************************************
588 ******************************************************************************/
589 HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
591 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
593 if (ppenumMoniker == NULL)
596 *ppenumMoniker = NULL;
601 /******************************************************************************
602 * ItemMoniker_IsEqual
603 ******************************************************************************/
604 HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
608 LPOLESTR dispName1,dispName2;
610 HRESULT res = S_FALSE;
612 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
614 if (!pmkOtherMoniker) return S_FALSE;
617 /* check if both are ItemMoniker */
618 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker,&clsid))) return S_FALSE;
619 if(!IsEqualCLSID(&clsid,&CLSID_ItemMoniker)) return S_FALSE;
621 /* check if both displaynames are the same */
622 if(SUCCEEDED ((res = CreateBindCtx(0,&bind)))) {
623 if(SUCCEEDED (IMoniker_GetDisplayName(iface,bind,NULL,&dispName1))) {
624 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&dispName2))) {
625 if(lstrcmpW(dispName1,dispName2)==0) res = S_OK;
626 CoTaskMemFree(dispName2);
628 CoTaskMemFree(dispName1);
634 /******************************************************************************
636 ******************************************************************************/
637 HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
639 ICOM_THIS(ItemMonikerImpl,iface);
641 int h = 0,i,skip,len;
648 val = This->itemName;
652 for (i = len ; i > 0; i--) {
653 h = (h * 37) + val[off++];
656 /* only sample some characters */
658 for (i = len ; i > 0; i -= skip, off += skip) {
659 h = (h * 39) + val[off];
668 /******************************************************************************
669 * ItemMoniker_IsRunning
670 ******************************************************************************/
671 HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface,
674 IMoniker* pmkNewlyRunning)
676 IRunningObjectTable* rot;
678 IOleItemContainer *poic=0;
679 ICOM_THIS(ItemMonikerImpl,iface);
681 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
683 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
684 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
686 if ((pmkNewlyRunning!=NULL)&&(IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK))
692 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
697 res = IRunningObjectTable_IsRunning(rot,iface);
699 IRunningObjectTable_Release(rot);
703 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
704 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
705 /* passing the string contained within this moniker. */
707 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic);
711 res=IOleItemContainer_IsRunning(poic,This->itemName);
713 IOleItemContainer_Release(poic);
720 /******************************************************************************
721 * ItemMoniker_GetTimeOfLastChange
722 ******************************************************************************/
723 HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
728 IRunningObjectTable* rot;
730 IMoniker *compositeMk;
732 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pItemTime);
737 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
740 return MK_E_NOTBINDABLE;
743 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
744 /* the time of last change. If the object is not in the ROT, the method calls */
745 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
747 res=CreateGenericComposite(pmkToLeft,iface,&compositeMk);
749 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
751 if (IRunningObjectTable_GetTimeOfLastChange(rot,compositeMk,pItemTime)!=S_OK)
753 res=IMoniker_GetTimeOfLastChange(pmkToLeft,pbc,NULL,pItemTime);
755 IMoniker_Release(compositeMk);
761 /******************************************************************************
762 * ItemMoniker_Inverse
763 ******************************************************************************/
764 HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
766 TRACE("(%p,%p)\n",iface,ppmk);
771 return CreateAntiMoniker(ppmk);
774 /******************************************************************************
775 * ItemMoniker_CommonPrefixWith
776 ******************************************************************************/
777 HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
780 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
781 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
782 /* to this moniker and returns MK_S_US */
784 if((mkSys==MKSYS_ITEMMONIKER) && (IMoniker_IsEqual(iface,pmkOther)==S_OK) ){
788 IMoniker_AddRef(iface);
793 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
794 /* the case where the other moniker is a generic composite. */
795 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
798 /******************************************************************************
799 * ItemMoniker_RelativePathTo
800 ******************************************************************************/
801 HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
803 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
805 if (ppmkRelPath==NULL)
810 return MK_E_NOTBINDABLE;
813 /******************************************************************************
814 * ItemMoniker_GetDisplayName
815 ******************************************************************************/
816 HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface,
819 LPOLESTR *ppszDisplayName)
821 ICOM_THIS(ItemMonikerImpl,iface);
823 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
825 if (ppszDisplayName==NULL)
828 if (pmkToLeft!=NULL){
832 *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(lstrlenW(This->itemDelimiter)+lstrlenW(This->itemName)+1));
834 if (*ppszDisplayName==NULL)
835 return E_OUTOFMEMORY;
837 lstrcpyW(*ppszDisplayName,This->itemDelimiter);
838 lstrcatW(*ppszDisplayName,This->itemName);
843 /******************************************************************************
844 * ItemMoniker_ParseDisplayName
845 ******************************************************************************/
846 HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker* iface,
849 LPOLESTR pszDisplayName,
853 IOleItemContainer* poic=0;
854 IParseDisplayName* ppdn=0;
855 LPOLESTR displayName;
857 ICOM_THIS(ItemMonikerImpl,iface);
859 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
865 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
866 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
867 /* name to IParseDisplayName::ParseDisplayName */
868 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic);
872 res=IOleItemContainer_GetObject(poic,This->itemName,BINDSPEED_MODERATE,pbc,&IID_IParseDisplayName,(void**)&ppdn);
874 res=IMoniker_GetDisplayName(iface,pbc,NULL,&displayName);
876 res=IParseDisplayName_ParseDisplayName(ppdn,pbc,displayName,pchEaten,ppmkOut);
878 IOleItemContainer_Release(poic);
879 IParseDisplayName_Release(ppdn);
885 /******************************************************************************
886 * ItemMoniker_IsSystemMoniker
887 ******************************************************************************/
888 HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
890 TRACE("(%p,%p)\n",iface,pwdMksys);
895 (*pwdMksys)=MKSYS_ITEMMONIKER;
900 /*******************************************************************************
901 * ItemMonikerIROTData_QueryInterface
902 *******************************************************************************/
903 HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
906 ICOM_THIS_From_IROTData(IMoniker, iface);
908 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
910 return ItemMonikerImpl_QueryInterface(This, riid, ppvObject);
913 /***********************************************************************
914 * ItemMonikerIROTData_AddRef
916 ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData *iface)
918 ICOM_THIS_From_IROTData(IMoniker, iface);
920 TRACE("(%p)\n",iface);
922 return ItemMonikerImpl_AddRef(This);
925 /***********************************************************************
926 * ItemMonikerIROTData_Release
928 ULONG WINAPI ItemMonikerROTDataImpl_Release(IROTData* iface)
930 ICOM_THIS_From_IROTData(IMoniker, iface);
932 TRACE("(%p)\n",iface);
934 return ItemMonikerImpl_Release(This);
937 /******************************************************************************
938 * ItemMonikerIROTData_GetComparaisonData
939 ******************************************************************************/
940 HRESULT WINAPI ItemMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
949 /******************************************************************************
950 * CreateItemMoniker16 [OLE2.28]
951 ******************************************************************************/
952 HRESULT WINAPI CreateItemMoniker16(LPCOLESTR16 lpszDelim,LPCOLESTR lpszItem,LPMONIKER* ppmk)
955 FIXME("(%s,%p),stub!\n",lpszDelim,ppmk);
960 /******************************************************************************
961 * CreateItemMoniker [OLE32.58]
962 ******************************************************************************/
963 HRESULT WINAPI CreateItemMoniker(LPCOLESTR lpszDelim,LPCOLESTR lpszItem, LPMONIKER * ppmk)
965 ItemMonikerImpl* newItemMoniker = 0;
967 IID riid=IID_IMoniker;
969 TRACE("(%p,%p,%p)\n",lpszDelim,lpszItem,ppmk);
971 newItemMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl));
973 if (newItemMoniker == 0)
974 return STG_E_INSUFFICIENTMEMORY;
976 hr = ItemMonikerImpl_Construct(newItemMoniker,lpszDelim,lpszItem);
980 HeapFree(GetProcessHeap(),0,newItemMoniker);
984 return ItemMonikerImpl_QueryInterface((IMoniker*)newItemMoniker,&riid,(void**)ppmk);