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 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
36 #include "wine/unicode.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole);
41 const CLSID CLSID_ItemMoniker = {
42 0x304, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
45 /* ItemMoniker data structure */
46 typedef struct ItemMonikerImpl{
48 IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/
50 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
51 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
53 IROTDataVtbl* lpvtbl2; /* VTable relative to the IROTData interface.*/
55 ULONG ref; /* reference counter for this object */
57 LPOLESTR itemName; /* item name identified by this ItemMoniker */
59 LPOLESTR itemDelimiter; /* Delimiter string */
61 IUnknown *pMarshal; /* custom marshaler */
64 /********************************************************************************/
65 /* ItemMoniker prototype functions : */
67 /* IUnknown prototype functions */
68 static HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
69 static ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface);
70 static ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface);
72 /* IPersist prototype functions */
73 static HRESULT WINAPI ItemMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
75 /* IPersistStream prototype functions */
76 static HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface);
77 static HRESULT WINAPI ItemMonikerImpl_Load(IMoniker* iface, IStream* pStm);
78 static HRESULT WINAPI ItemMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
79 static HRESULT WINAPI ItemMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
81 /* IMoniker prototype functions */
82 static HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
83 static HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
84 static HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
85 static HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
86 static HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
87 static HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
88 static HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
89 static HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
90 static HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pItemTime);
91 static HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
92 static HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
93 static HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
94 static HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
95 static HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
96 static HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
98 /* Local function used by ItemMoniker implementation */
99 HRESULT WINAPI ItemMonikerImpl_Construct(ItemMonikerImpl* iface, LPCOLESTR lpszDelim,LPCOLESTR lpszPathName);
100 HRESULT WINAPI ItemMonikerImpl_Destroy(ItemMonikerImpl* iface);
102 /********************************************************************************/
103 /* IROTData prototype functions */
105 /* IUnknown prototype functions */
106 static HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
107 static ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData* iface);
108 static ULONG WINAPI ItemMonikerROTDataImpl_Release(IROTData* iface);
110 /* IROTData prototype function */
111 static HRESULT WINAPI ItemMonikerROTDataImpl_GetComparisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
113 /********************************************************************************/
114 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
115 /* IPersistStream and IMoniker functions. */
116 static IMonikerVtbl VT_ItemMonikerImpl =
118 ItemMonikerImpl_QueryInterface,
119 ItemMonikerImpl_AddRef,
120 ItemMonikerImpl_Release,
121 ItemMonikerImpl_GetClassID,
122 ItemMonikerImpl_IsDirty,
123 ItemMonikerImpl_Load,
124 ItemMonikerImpl_Save,
125 ItemMonikerImpl_GetSizeMax,
126 ItemMonikerImpl_BindToObject,
127 ItemMonikerImpl_BindToStorage,
128 ItemMonikerImpl_Reduce,
129 ItemMonikerImpl_ComposeWith,
130 ItemMonikerImpl_Enum,
131 ItemMonikerImpl_IsEqual,
132 ItemMonikerImpl_Hash,
133 ItemMonikerImpl_IsRunning,
134 ItemMonikerImpl_GetTimeOfLastChange,
135 ItemMonikerImpl_Inverse,
136 ItemMonikerImpl_CommonPrefixWith,
137 ItemMonikerImpl_RelativePathTo,
138 ItemMonikerImpl_GetDisplayName,
139 ItemMonikerImpl_ParseDisplayName,
140 ItemMonikerImpl_IsSystemMoniker
143 /********************************************************************************/
144 /* Virtual function table for the IROTData class. */
145 static IROTDataVtbl VT_ROTDataImpl =
147 ItemMonikerROTDataImpl_QueryInterface,
148 ItemMonikerROTDataImpl_AddRef,
149 ItemMonikerROTDataImpl_Release,
150 ItemMonikerROTDataImpl_GetComparisonData
153 /*******************************************************************************
154 * ItemMoniker_QueryInterface
155 *******************************************************************************/
156 HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
158 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
160 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppvObject);
162 /* Perform a sanity check on the parameters.*/
163 if ( (This==0) || (ppvObject==0) )
166 /* Initialize the return parameter */
169 /* Compare the riid with the interface IDs implemented by this object.*/
170 if (IsEqualIID(&IID_IUnknown, riid) ||
171 IsEqualIID(&IID_IPersist, riid) ||
172 IsEqualIID(&IID_IPersistStream, riid) ||
173 IsEqualIID(&IID_IMoniker, riid)
177 else if (IsEqualIID(&IID_IROTData, riid))
178 *ppvObject = (IROTData*)&(This->lpvtbl2);
179 else if (IsEqualIID(&IID_IMarshal, riid))
183 hr = MonikerMarshal_Create(iface, &This->pMarshal);
186 return IUnknown_QueryInterface(This->pMarshal, riid, ppvObject);
189 /* Check that we obtained an interface.*/
191 return E_NOINTERFACE;
193 /* Query Interface always increases the reference count by one when it is successful */
194 ItemMonikerImpl_AddRef(iface);
199 /******************************************************************************
201 ******************************************************************************/
202 ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface)
204 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
206 TRACE("(%p)\n",This);
208 return InterlockedIncrement(&This->ref);
211 /******************************************************************************
212 * ItemMoniker_Release
213 ******************************************************************************/
214 ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface)
216 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
219 TRACE("(%p)\n",This);
221 ref = InterlockedDecrement(&This->ref);
223 /* destroy the object if there's no more reference on it */
224 if (ref == 0) ItemMonikerImpl_Destroy(This);
229 /******************************************************************************
230 * ItemMoniker_GetClassID
231 ******************************************************************************/
232 HRESULT WINAPI ItemMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
234 TRACE("(%p,%p)\n",iface,pClassID);
239 *pClassID = CLSID_ItemMoniker;
244 /******************************************************************************
245 * ItemMoniker_IsDirty
246 ******************************************************************************/
247 HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface)
249 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
250 method in the OLE-provided moniker interfaces always return S_FALSE because
251 their internal state never changes. */
253 TRACE("(%p)\n",iface);
258 /******************************************************************************
260 ******************************************************************************/
261 HRESULT WINAPI ItemMonikerImpl_Load(IMoniker* iface,IStream* pStm)
264 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
266 DWORD delimiterLength,nameLength,lenW;
267 CHAR *itemNameA,*itemDelimiterA;
272 /* for more details about data read by this function see coments of ItemMonikerImpl_Save function */
274 /* read item delimiter string length + 1 */
275 res=IStream_Read(pStm,&delimiterLength,sizeof(DWORD),&bread);
276 if (bread != sizeof(DWORD))
279 /* read item delimiter string */
280 if (!(itemDelimiterA=HeapAlloc(GetProcessHeap(),0,delimiterLength)))
281 return E_OUTOFMEMORY;
282 res=IStream_Read(pStm,itemDelimiterA,delimiterLength,&bread);
283 if (bread != delimiterLength)
285 HeapFree( GetProcessHeap(), 0, itemDelimiterA );
289 lenW = MultiByteToWideChar( CP_ACP, 0, itemDelimiterA, -1, NULL, 0 );
290 This->itemDelimiter=HeapReAlloc(GetProcessHeap(),0,This->itemDelimiter,lenW*sizeof(WCHAR));
291 if (!This->itemDelimiter)
293 HeapFree( GetProcessHeap(), 0, itemDelimiterA );
294 return E_OUTOFMEMORY;
296 MultiByteToWideChar( CP_ACP, 0, itemDelimiterA, -1, This->itemDelimiter, lenW );
297 HeapFree( GetProcessHeap(), 0, itemDelimiterA );
299 /* read item name string length + 1*/
300 res=IStream_Read(pStm,&nameLength,sizeof(DWORD),&bread);
301 if (bread != sizeof(DWORD))
304 /* read item name string */
305 if (!(itemNameA=HeapAlloc(GetProcessHeap(),0,nameLength)))
306 return E_OUTOFMEMORY;
307 res=IStream_Read(pStm,itemNameA,nameLength,&bread);
308 if (bread != nameLength)
310 HeapFree( GetProcessHeap(), 0, itemNameA );
314 lenW = MultiByteToWideChar( CP_ACP, 0, itemNameA, -1, NULL, 0 );
315 This->itemName=HeapReAlloc(GetProcessHeap(),0,This->itemName,lenW*sizeof(WCHAR));
318 HeapFree( GetProcessHeap(), 0, itemNameA );
319 return E_OUTOFMEMORY;
321 MultiByteToWideChar( CP_ACP, 0, itemNameA, -1, This->itemName, lenW );
322 HeapFree( GetProcessHeap(), 0, itemNameA );
327 /******************************************************************************
329 ******************************************************************************/
330 HRESULT WINAPI ItemMonikerImpl_Save(IMoniker* iface,
331 IStream* pStm,/* pointer to the stream where the object is to be saved */
332 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
334 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
336 CHAR *itemNameA,*itemDelimiterA;
338 /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
339 /* 2) String (type A): item delimiter string ('\0' included) */
340 /* 3) DWORD : size of item name string ('\0' included) */
341 /* 4) String (type A): item name string ('\0' included) */
343 DWORD nameLength = WideCharToMultiByte( CP_ACP, 0, This->itemName, -1, NULL, 0, NULL, NULL);
344 DWORD delimiterLength = WideCharToMultiByte( CP_ACP, 0, This->itemDelimiter, -1, NULL, 0, NULL, NULL);
345 itemNameA=HeapAlloc(GetProcessHeap(),0,nameLength);
346 itemDelimiterA=HeapAlloc(GetProcessHeap(),0,delimiterLength);
347 WideCharToMultiByte( CP_ACP, 0, This->itemName, -1, itemNameA, nameLength, NULL, NULL);
348 WideCharToMultiByte( CP_ACP, 0, This->itemDelimiter, -1, itemDelimiterA, delimiterLength, NULL, NULL);
350 TRACE("%p, %s\n", pStm, fClearDirty ? "TRUE" : "FALSE");
352 res=IStream_Write(pStm,&delimiterLength,sizeof(DWORD),NULL);
353 res=IStream_Write(pStm,itemDelimiterA,delimiterLength * sizeof(CHAR),NULL);
354 res=IStream_Write(pStm,&nameLength,sizeof(DWORD),NULL);
355 res=IStream_Write(pStm,itemNameA,nameLength * sizeof(CHAR),NULL);
360 /******************************************************************************
361 * ItemMoniker_GetSizeMax
362 ******************************************************************************/
363 HRESULT WINAPI ItemMonikerImpl_GetSizeMax(IMoniker* iface,
364 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
366 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
367 DWORD delimiterLength=lstrlenW(This->itemDelimiter)+1;
368 DWORD nameLength=lstrlenW(This->itemName)+1;
370 TRACE("(%p,%p)\n",iface,pcbSize);
375 /* for more details see ItemMonikerImpl_Save coments */
377 pcbSize->u.LowPart = sizeof(DWORD) + /* DWORD which contains delimiter length */
378 delimiterLength + /* item delimiter string */
379 sizeof(DWORD) + /* DWORD which contains item name length */
380 nameLength + /* item name string */
381 34; /* this constant was added ! because when I tested this function it usually */
382 /* returns 34 bytes more than the number of bytes used by IMoniker::Save function */
383 pcbSize->u.HighPart=0;
388 /******************************************************************************
389 * ItemMoniker_Construct (local function)
390 *******************************************************************************/
391 HRESULT WINAPI ItemMonikerImpl_Construct(ItemMonikerImpl* This, LPCOLESTR lpszDelim,LPCOLESTR lpszItem)
394 int sizeStr1=lstrlenW(lpszItem), sizeStr2;
395 static const OLECHAR emptystr[1];
398 TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszDelim),debugstr_w(lpszItem));
400 /* Initialize the virtual fgunction table. */
401 This->lpvtbl1 = &VT_ItemMonikerImpl;
402 This->lpvtbl2 = &VT_ROTDataImpl;
404 This->pMarshal = NULL;
406 This->itemName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr1+1));
408 return E_OUTOFMEMORY;
409 lstrcpyW(This->itemName,lpszItem);
412 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
414 delim = lpszDelim ? lpszDelim : emptystr;
416 sizeStr2=lstrlenW(delim);
417 This->itemDelimiter=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr2+1));
418 if (!This->itemDelimiter) {
419 HeapFree(GetProcessHeap(),0,This->itemName);
420 return E_OUTOFMEMORY;
422 lstrcpyW(This->itemDelimiter,delim);
426 /******************************************************************************
427 * ItemMoniker_Destroy (local function)
428 *******************************************************************************/
429 HRESULT WINAPI ItemMonikerImpl_Destroy(ItemMonikerImpl* This)
431 TRACE("(%p)\n",This);
433 if (This->pMarshal) IUnknown_Release(This->pMarshal);
434 HeapFree(GetProcessHeap(),0,This->itemName);
435 HeapFree(GetProcessHeap(),0,This->itemDelimiter);
436 HeapFree(GetProcessHeap(),0,This);
441 /******************************************************************************
442 * ItemMoniker_BindToObject
443 ******************************************************************************/
444 HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface,
450 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
453 IID refid=IID_IOleItemContainer;
454 IOleItemContainer *poic=0;
456 TRACE("(%p,%p,%p,%s,%p)\n",iface,pbc,pmkToLeft,debugstr_guid(riid),ppvResult);
466 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&refid,(void**)&poic);
470 res=IOleItemContainer_GetObject(poic,This->itemName,BINDSPEED_MODERATE,pbc,riid,ppvResult);
472 IOleItemContainer_Release(poic);
478 /******************************************************************************
479 * ItemMoniker_BindToStorage
480 ******************************************************************************/
481 HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker* iface,
487 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
490 IOleItemContainer *poic=0;
492 TRACE("(%p,%p,%p,%s,%p)\n",iface,pbc,pmkToLeft,debugstr_guid(riid),ppvResult);
499 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic);
503 res=IOleItemContainer_GetObjectStorage(poic,This->itemName,pbc,riid,ppvResult);
505 IOleItemContainer_Release(poic);
511 /******************************************************************************
513 ******************************************************************************/
514 HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface,
516 DWORD dwReduceHowFar,
517 IMoniker** ppmkToLeft,
518 IMoniker** ppmkReduced)
520 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
522 if (ppmkReduced==NULL)
525 ItemMonikerImpl_AddRef(iface);
529 return MK_S_REDUCED_TO_SELF;
531 /******************************************************************************
532 * ItemMoniker_ComposeWith
533 ******************************************************************************/
534 HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface,
536 BOOL fOnlyIfNotGeneric,
537 IMoniker** ppmkComposite)
541 IEnumMoniker* penumMk=0;
542 IMoniker *pmostLeftMk=0;
543 IMoniker* tempMkComposite=0;
545 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
547 if ((ppmkComposite==NULL)||(pmkRight==NULL))
552 IMoniker_IsSystemMoniker(pmkRight,&mkSys);
554 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
555 if(mkSys==MKSYS_ANTIMONIKER)
559 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
560 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
562 if(mkSys==MKSYS_GENERICCOMPOSITE){
564 res=IMoniker_Enum(pmkRight,TRUE,&penumMk);
569 res=IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL);
571 IMoniker_IsSystemMoniker(pmostLeftMk,&mkSys2);
573 if(mkSys2==MKSYS_ANTIMONIKER){
575 IMoniker_Release(pmostLeftMk);
577 tempMkComposite=iface;
578 IMoniker_AddRef(iface);
580 while(IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL)==S_OK){
582 res=CreateGenericComposite(tempMkComposite,pmostLeftMk,ppmkComposite);
584 IMoniker_Release(tempMkComposite);
585 IMoniker_Release(pmostLeftMk);
587 tempMkComposite=*ppmkComposite;
588 IMoniker_AddRef(tempMkComposite);
593 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
595 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
596 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
597 a NULL moniker and a return value of MK_E_NEEDGENERIC */
599 if (!fOnlyIfNotGeneric)
600 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
603 return MK_E_NEEDGENERIC;
606 /******************************************************************************
608 ******************************************************************************/
609 HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
611 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
613 if (ppenumMoniker == NULL)
616 *ppenumMoniker = NULL;
621 /******************************************************************************
622 * ItemMoniker_IsEqual
623 ******************************************************************************/
624 HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
628 LPOLESTR dispName1,dispName2;
630 HRESULT res = S_FALSE;
632 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
634 if (!pmkOtherMoniker) return S_FALSE;
637 /* check if both are ItemMoniker */
638 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker,&clsid))) return S_FALSE;
639 if(!IsEqualCLSID(&clsid,&CLSID_ItemMoniker)) return S_FALSE;
641 /* check if both displaynames are the same */
642 if(SUCCEEDED ((res = CreateBindCtx(0,&bind)))) {
643 if(SUCCEEDED (IMoniker_GetDisplayName(iface,bind,NULL,&dispName1))) {
644 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&dispName2))) {
645 if(lstrcmpW(dispName1,dispName2)==0) res = S_OK;
646 CoTaskMemFree(dispName2);
648 CoTaskMemFree(dispName1);
654 /******************************************************************************
656 ******************************************************************************/
657 HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
659 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
661 int h = 0,i,skip,len;
668 val = This->itemName;
672 for (i = len ; i > 0; i--) {
673 h = (h * 37) + val[off++];
676 /* only sample some characters */
678 for (i = len ; i > 0; i -= skip, off += skip) {
679 h = (h * 39) + val[off];
688 /******************************************************************************
689 * ItemMoniker_IsRunning
690 ******************************************************************************/
691 HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface,
694 IMoniker* pmkNewlyRunning)
696 IRunningObjectTable* rot;
698 IOleItemContainer *poic=0;
699 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
701 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
703 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
704 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
706 if ((pmkNewlyRunning!=NULL)&&(IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK))
712 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
717 res = IRunningObjectTable_IsRunning(rot,iface);
719 IRunningObjectTable_Release(rot);
723 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
724 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
725 /* passing the string contained within this moniker. */
727 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic);
731 res=IOleItemContainer_IsRunning(poic,This->itemName);
733 IOleItemContainer_Release(poic);
740 /******************************************************************************
741 * ItemMoniker_GetTimeOfLastChange
742 ******************************************************************************/
743 HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
748 IRunningObjectTable* rot;
750 IMoniker *compositeMk;
752 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pItemTime);
757 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
760 return MK_E_NOTBINDABLE;
763 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
764 /* the time of last change. If the object is not in the ROT, the method calls */
765 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
767 res=CreateGenericComposite(pmkToLeft,iface,&compositeMk);
769 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
771 if (IRunningObjectTable_GetTimeOfLastChange(rot,compositeMk,pItemTime)!=S_OK)
773 res=IMoniker_GetTimeOfLastChange(pmkToLeft,pbc,NULL,pItemTime);
775 IMoniker_Release(compositeMk);
781 /******************************************************************************
782 * ItemMoniker_Inverse
783 ******************************************************************************/
784 HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
786 TRACE("(%p,%p)\n",iface,ppmk);
791 return CreateAntiMoniker(ppmk);
794 /******************************************************************************
795 * ItemMoniker_CommonPrefixWith
796 ******************************************************************************/
797 HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
801 TRACE("(%p,%p)\n", pmkOther, ppmkPrefix);
803 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
804 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
805 /* to this moniker and returns MK_S_US */
807 if((mkSys==MKSYS_ITEMMONIKER) && (IMoniker_IsEqual(iface,pmkOther)==S_OK) ){
811 IMoniker_AddRef(iface);
816 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
817 /* the case where the other moniker is a generic composite. */
818 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
821 /******************************************************************************
822 * ItemMoniker_RelativePathTo
823 ******************************************************************************/
824 HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
826 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
828 if (ppmkRelPath==NULL)
833 return MK_E_NOTBINDABLE;
836 /******************************************************************************
837 * ItemMoniker_GetDisplayName
838 ******************************************************************************/
839 HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface,
842 LPOLESTR *ppszDisplayName)
844 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
846 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
848 if (ppszDisplayName==NULL)
851 if (pmkToLeft!=NULL){
855 *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(lstrlenW(This->itemDelimiter)+lstrlenW(This->itemName)+1));
857 if (*ppszDisplayName==NULL)
858 return E_OUTOFMEMORY;
860 lstrcpyW(*ppszDisplayName,This->itemDelimiter);
861 lstrcatW(*ppszDisplayName,This->itemName);
863 TRACE("-- %s\n", debugstr_w(*ppszDisplayName));
868 /******************************************************************************
869 * ItemMoniker_ParseDisplayName
870 ******************************************************************************/
871 HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker* iface,
874 LPOLESTR pszDisplayName,
878 IOleItemContainer* poic=0;
879 IParseDisplayName* ppdn=0;
880 LPOLESTR displayName;
882 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
884 TRACE("%s\n", debugstr_w(pszDisplayName));
886 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
892 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
893 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
894 /* name to IParseDisplayName::ParseDisplayName */
895 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic);
899 res=IOleItemContainer_GetObject(poic,This->itemName,BINDSPEED_MODERATE,pbc,&IID_IParseDisplayName,(void**)&ppdn);
901 res=IMoniker_GetDisplayName(iface,pbc,NULL,&displayName);
903 res=IParseDisplayName_ParseDisplayName(ppdn,pbc,displayName,pchEaten,ppmkOut);
905 IOleItemContainer_Release(poic);
906 IParseDisplayName_Release(ppdn);
912 /******************************************************************************
913 * ItemMoniker_IsSystemMoniker
914 ******************************************************************************/
915 HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
917 TRACE("(%p,%p)\n",iface,pwdMksys);
922 (*pwdMksys)=MKSYS_ITEMMONIKER;
927 /*******************************************************************************
928 * ItemMonikerIROTData_QueryInterface
929 *******************************************************************************/
930 HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
933 ICOM_THIS_From_IROTData(IMoniker, iface);
935 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
937 return ItemMonikerImpl_QueryInterface(This, riid, ppvObject);
940 /***********************************************************************
941 * ItemMonikerIROTData_AddRef
943 ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData *iface)
945 ICOM_THIS_From_IROTData(IMoniker, iface);
947 TRACE("(%p)\n",iface);
949 return ItemMonikerImpl_AddRef(This);
952 /***********************************************************************
953 * ItemMonikerIROTData_Release
955 ULONG WINAPI ItemMonikerROTDataImpl_Release(IROTData* iface)
957 ICOM_THIS_From_IROTData(IMoniker, iface);
959 TRACE("(%p)\n",iface);
961 return ItemMonikerImpl_Release(This);
964 /******************************************************************************
965 * ItemMonikerIROTData_GetComparaisonData
966 ******************************************************************************/
967 HRESULT WINAPI ItemMonikerROTDataImpl_GetComparisonData(IROTData* iface,
972 ICOM_THIS_From_IROTData(IMoniker, iface);
973 ItemMonikerImpl *This1 = (ItemMonikerImpl *)This;
974 int len = (strlenW(This1->itemName)+1);
977 LPWSTR pszItemDelimiter;
979 TRACE("(%p, %lu, %p)\n", pbData, cbMax, pcbData);
981 *pcbData = sizeof(CLSID) + sizeof(WCHAR) + len * sizeof(WCHAR);
982 if (cbMax < *pcbData)
983 return E_OUTOFMEMORY;
986 memcpy(pbData, &CLSID_ItemMoniker, sizeof(CLSID));
987 /* write delimiter */
988 pszItemDelimiter = (LPWSTR)(pbData+sizeof(CLSID));
989 *pszItemDelimiter = *This1->itemDelimiter;
991 pszItemName = pszItemDelimiter + 1;
992 for (i = 0; i < len; i++)
993 pszItemName[i] = toupperW(This1->itemName[i]);
998 /******************************************************************************
999 * CreateItemMoniker [OLE32.@]
1000 ******************************************************************************/
1001 HRESULT WINAPI CreateItemMoniker(LPCOLESTR lpszDelim,LPCOLESTR lpszItem, LPMONIKER * ppmk)
1003 ItemMonikerImpl* newItemMoniker;
1006 TRACE("(%s,%s,%p)\n",debugstr_w(lpszDelim),debugstr_w(lpszItem),ppmk);
1008 newItemMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl));
1010 if (!newItemMoniker)
1011 return STG_E_INSUFFICIENTMEMORY;
1013 hr = ItemMonikerImpl_Construct(newItemMoniker,lpszDelim,lpszItem);
1017 HeapFree(GetProcessHeap(),0,newItemMoniker);
1021 return ItemMonikerImpl_QueryInterface((IMoniker*)newItemMoniker,&IID_IMoniker,(void**)ppmk);
1024 static HRESULT WINAPI ItemMonikerCF_QueryInterface(LPCLASSFACTORY iface,
1025 REFIID riid, LPVOID *ppv)
1028 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
1031 IUnknown_AddRef(iface);
1034 return E_NOINTERFACE;
1037 static ULONG WINAPI ItemMonikerCF_AddRef(LPCLASSFACTORY iface)
1039 return 2; /* non-heap based object */
1042 static ULONG WINAPI ItemMonikerCF_Release(LPCLASSFACTORY iface)
1044 return 1; /* non-heap based object */
1047 static HRESULT WINAPI ItemMonikerCF_CreateInstance(LPCLASSFACTORY iface,
1048 LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
1050 ItemMonikerImpl* newItemMoniker;
1052 static const WCHAR wszEmpty[] = { 0 };
1054 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);
1059 return CLASS_E_NOAGGREGATION;
1061 newItemMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl));
1062 if (!newItemMoniker)
1063 return E_OUTOFMEMORY;
1065 hr = ItemMonikerImpl_Construct(newItemMoniker, wszEmpty, wszEmpty);
1068 hr = ItemMonikerImpl_QueryInterface((IMoniker*)newItemMoniker, riid, ppv);
1070 HeapFree(GetProcessHeap(),0,newItemMoniker);
1075 static HRESULT WINAPI ItemMonikerCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
1077 FIXME("(%d), stub!\n",fLock);
1081 static const IClassFactoryVtbl ItemMonikerCFVtbl =
1083 ItemMonikerCF_QueryInterface,
1084 ItemMonikerCF_AddRef,
1085 ItemMonikerCF_Release,
1086 ItemMonikerCF_CreateInstance,
1087 ItemMonikerCF_LockServer
1089 static const IClassFactoryVtbl *ItemMonikerCF = &ItemMonikerCFVtbl;
1091 HRESULT ItemMonikerCF_Create(REFIID riid, LPVOID *ppv)
1093 return IClassFactory_QueryInterface((IClassFactory *)&ItemMonikerCF, riid, ppv);