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 const 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 const IROTDataVtbl* lpvtbl2; /* VTable relative to the IROTData interface.*/
55 LONG 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 static inline IMoniker *impl_from_IROTData( IROTData *iface )
66 return (IMoniker *)((char*)iface - FIELD_OFFSET(ItemMonikerImpl, lpvtbl2));
69 /********************************************************************************/
70 /* ItemMoniker prototype functions : */
72 /* IUnknown prototype functions */
73 static HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
74 static ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface);
75 static ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface);
77 /* IPersist prototype functions */
78 static HRESULT WINAPI ItemMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
80 /* IPersistStream prototype functions */
81 static HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface);
82 static HRESULT WINAPI ItemMonikerImpl_Load(IMoniker* iface, IStream* pStm);
83 static HRESULT WINAPI ItemMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
84 static HRESULT WINAPI ItemMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
86 /* IMoniker prototype functions */
87 static HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
88 static HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
89 static HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
90 static HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
91 static HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
92 static HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
93 static HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
94 static HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
95 static HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pItemTime);
96 static HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
97 static HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
98 static HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
99 static HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
100 static HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
101 static HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
103 /* Local function used by ItemMoniker implementation */
104 HRESULT WINAPI ItemMonikerImpl_Construct(ItemMonikerImpl* iface, LPCOLESTR lpszDelim,LPCOLESTR lpszPathName);
105 HRESULT WINAPI ItemMonikerImpl_Destroy(ItemMonikerImpl* iface);
107 /********************************************************************************/
108 /* IROTData prototype functions */
110 /* IUnknown prototype functions */
111 static HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
112 static ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData* iface);
113 static ULONG WINAPI ItemMonikerROTDataImpl_Release(IROTData* iface);
115 /* IROTData prototype function */
116 static HRESULT WINAPI ItemMonikerROTDataImpl_GetComparisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
118 /********************************************************************************/
119 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
120 /* IPersistStream and IMoniker functions. */
121 static const IMonikerVtbl VT_ItemMonikerImpl =
123 ItemMonikerImpl_QueryInterface,
124 ItemMonikerImpl_AddRef,
125 ItemMonikerImpl_Release,
126 ItemMonikerImpl_GetClassID,
127 ItemMonikerImpl_IsDirty,
128 ItemMonikerImpl_Load,
129 ItemMonikerImpl_Save,
130 ItemMonikerImpl_GetSizeMax,
131 ItemMonikerImpl_BindToObject,
132 ItemMonikerImpl_BindToStorage,
133 ItemMonikerImpl_Reduce,
134 ItemMonikerImpl_ComposeWith,
135 ItemMonikerImpl_Enum,
136 ItemMonikerImpl_IsEqual,
137 ItemMonikerImpl_Hash,
138 ItemMonikerImpl_IsRunning,
139 ItemMonikerImpl_GetTimeOfLastChange,
140 ItemMonikerImpl_Inverse,
141 ItemMonikerImpl_CommonPrefixWith,
142 ItemMonikerImpl_RelativePathTo,
143 ItemMonikerImpl_GetDisplayName,
144 ItemMonikerImpl_ParseDisplayName,
145 ItemMonikerImpl_IsSystemMoniker
148 /********************************************************************************/
149 /* Virtual function table for the IROTData class. */
150 static const IROTDataVtbl VT_ROTDataImpl =
152 ItemMonikerROTDataImpl_QueryInterface,
153 ItemMonikerROTDataImpl_AddRef,
154 ItemMonikerROTDataImpl_Release,
155 ItemMonikerROTDataImpl_GetComparisonData
158 /*******************************************************************************
159 * ItemMoniker_QueryInterface
160 *******************************************************************************/
161 HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
163 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
165 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppvObject);
167 /* Perform a sanity check on the parameters.*/
168 if ( (This==0) || (ppvObject==0) )
171 /* Initialize the return parameter */
174 /* Compare the riid with the interface IDs implemented by this object.*/
175 if (IsEqualIID(&IID_IUnknown, riid) ||
176 IsEqualIID(&IID_IPersist, riid) ||
177 IsEqualIID(&IID_IPersistStream, riid) ||
178 IsEqualIID(&IID_IMoniker, riid)
182 else if (IsEqualIID(&IID_IROTData, riid))
183 *ppvObject = (IROTData*)&(This->lpvtbl2);
184 else if (IsEqualIID(&IID_IMarshal, riid))
188 hr = MonikerMarshal_Create(iface, &This->pMarshal);
191 return IUnknown_QueryInterface(This->pMarshal, riid, ppvObject);
194 /* Check that we obtained an interface.*/
196 return E_NOINTERFACE;
198 /* Query Interface always increases the reference count by one when it is successful */
199 ItemMonikerImpl_AddRef(iface);
204 /******************************************************************************
206 ******************************************************************************/
207 ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface)
209 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
211 TRACE("(%p)\n",This);
213 return InterlockedIncrement(&This->ref);
216 /******************************************************************************
217 * ItemMoniker_Release
218 ******************************************************************************/
219 ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface)
221 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
224 TRACE("(%p)\n",This);
226 ref = InterlockedDecrement(&This->ref);
228 /* destroy the object if there's no more reference on it */
229 if (ref == 0) ItemMonikerImpl_Destroy(This);
234 /******************************************************************************
235 * ItemMoniker_GetClassID
236 ******************************************************************************/
237 HRESULT WINAPI ItemMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
239 TRACE("(%p,%p)\n",iface,pClassID);
244 *pClassID = CLSID_ItemMoniker;
249 /******************************************************************************
250 * ItemMoniker_IsDirty
251 ******************************************************************************/
252 HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface)
254 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
255 method in the OLE-provided moniker interfaces always return S_FALSE because
256 their internal state never changes. */
258 TRACE("(%p)\n",iface);
263 /******************************************************************************
265 ******************************************************************************/
266 HRESULT WINAPI ItemMonikerImpl_Load(IMoniker* iface,IStream* pStm)
269 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
271 DWORD delimiterLength,nameLength,lenW;
272 CHAR *itemNameA,*itemDelimiterA;
277 /* for more details about data read by this function see coments of ItemMonikerImpl_Save function */
279 /* read item delimiter string length + 1 */
280 res=IStream_Read(pStm,&delimiterLength,sizeof(DWORD),&bread);
281 if (bread != sizeof(DWORD))
284 /* read item delimiter string */
285 if (!(itemDelimiterA=HeapAlloc(GetProcessHeap(),0,delimiterLength)))
286 return E_OUTOFMEMORY;
287 res=IStream_Read(pStm,itemDelimiterA,delimiterLength,&bread);
288 if (bread != delimiterLength)
290 HeapFree( GetProcessHeap(), 0, itemDelimiterA );
294 lenW = MultiByteToWideChar( CP_ACP, 0, itemDelimiterA, -1, NULL, 0 );
295 This->itemDelimiter=HeapReAlloc(GetProcessHeap(),0,This->itemDelimiter,lenW*sizeof(WCHAR));
296 if (!This->itemDelimiter)
298 HeapFree( GetProcessHeap(), 0, itemDelimiterA );
299 return E_OUTOFMEMORY;
301 MultiByteToWideChar( CP_ACP, 0, itemDelimiterA, -1, This->itemDelimiter, lenW );
302 HeapFree( GetProcessHeap(), 0, itemDelimiterA );
304 /* read item name string length + 1*/
305 res=IStream_Read(pStm,&nameLength,sizeof(DWORD),&bread);
306 if (bread != sizeof(DWORD))
309 /* read item name string */
310 if (!(itemNameA=HeapAlloc(GetProcessHeap(),0,nameLength)))
311 return E_OUTOFMEMORY;
312 res=IStream_Read(pStm,itemNameA,nameLength,&bread);
313 if (bread != nameLength)
315 HeapFree( GetProcessHeap(), 0, itemNameA );
319 lenW = MultiByteToWideChar( CP_ACP, 0, itemNameA, -1, NULL, 0 );
320 This->itemName=HeapReAlloc(GetProcessHeap(),0,This->itemName,lenW*sizeof(WCHAR));
323 HeapFree( GetProcessHeap(), 0, itemNameA );
324 return E_OUTOFMEMORY;
326 MultiByteToWideChar( CP_ACP, 0, itemNameA, -1, This->itemName, lenW );
327 HeapFree( GetProcessHeap(), 0, itemNameA );
332 /******************************************************************************
334 ******************************************************************************/
335 HRESULT WINAPI ItemMonikerImpl_Save(IMoniker* iface,
336 IStream* pStm,/* pointer to the stream where the object is to be saved */
337 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
339 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
341 CHAR *itemNameA,*itemDelimiterA;
343 /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
344 /* 2) String (type A): item delimiter string ('\0' included) */
345 /* 3) DWORD : size of item name string ('\0' included) */
346 /* 4) String (type A): item name string ('\0' included) */
348 DWORD nameLength = WideCharToMultiByte( CP_ACP, 0, This->itemName, -1, NULL, 0, NULL, NULL);
349 DWORD delimiterLength = WideCharToMultiByte( CP_ACP, 0, This->itemDelimiter, -1, NULL, 0, NULL, NULL);
350 itemNameA=HeapAlloc(GetProcessHeap(),0,nameLength);
351 itemDelimiterA=HeapAlloc(GetProcessHeap(),0,delimiterLength);
352 WideCharToMultiByte( CP_ACP, 0, This->itemName, -1, itemNameA, nameLength, NULL, NULL);
353 WideCharToMultiByte( CP_ACP, 0, This->itemDelimiter, -1, itemDelimiterA, delimiterLength, NULL, NULL);
355 TRACE("%p, %s\n", pStm, fClearDirty ? "TRUE" : "FALSE");
357 res=IStream_Write(pStm,&delimiterLength,sizeof(DWORD),NULL);
358 res=IStream_Write(pStm,itemDelimiterA,delimiterLength * sizeof(CHAR),NULL);
359 res=IStream_Write(pStm,&nameLength,sizeof(DWORD),NULL);
360 res=IStream_Write(pStm,itemNameA,nameLength * sizeof(CHAR),NULL);
365 /******************************************************************************
366 * ItemMoniker_GetSizeMax
367 ******************************************************************************/
368 HRESULT WINAPI ItemMonikerImpl_GetSizeMax(IMoniker* iface,
369 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
371 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
372 DWORD delimiterLength=lstrlenW(This->itemDelimiter)+1;
373 DWORD nameLength=lstrlenW(This->itemName)+1;
375 TRACE("(%p,%p)\n",iface,pcbSize);
380 /* for more details see ItemMonikerImpl_Save coments */
382 pcbSize->u.LowPart = sizeof(DWORD) + /* DWORD which contains delimiter length */
383 delimiterLength*4 + /* item delimiter string */
384 sizeof(DWORD) + /* DWORD which contains item name length */
385 nameLength*4 + /* item name string */
386 18; /* strange, but true */
387 pcbSize->u.HighPart=0;
392 /******************************************************************************
393 * ItemMoniker_Construct (local function)
394 *******************************************************************************/
395 HRESULT WINAPI ItemMonikerImpl_Construct(ItemMonikerImpl* This, LPCOLESTR lpszDelim,LPCOLESTR lpszItem)
398 int sizeStr1=lstrlenW(lpszItem), sizeStr2;
399 static const OLECHAR emptystr[1];
402 TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszDelim),debugstr_w(lpszItem));
404 /* Initialize the virtual fgunction table. */
405 This->lpvtbl1 = &VT_ItemMonikerImpl;
406 This->lpvtbl2 = &VT_ROTDataImpl;
408 This->pMarshal = NULL;
410 This->itemName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr1+1));
412 return E_OUTOFMEMORY;
413 lstrcpyW(This->itemName,lpszItem);
416 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
418 delim = lpszDelim ? lpszDelim : emptystr;
420 sizeStr2=lstrlenW(delim);
421 This->itemDelimiter=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr2+1));
422 if (!This->itemDelimiter) {
423 HeapFree(GetProcessHeap(),0,This->itemName);
424 return E_OUTOFMEMORY;
426 lstrcpyW(This->itemDelimiter,delim);
430 /******************************************************************************
431 * ItemMoniker_Destroy (local function)
432 *******************************************************************************/
433 HRESULT WINAPI ItemMonikerImpl_Destroy(ItemMonikerImpl* This)
435 TRACE("(%p)\n",This);
437 if (This->pMarshal) IUnknown_Release(This->pMarshal);
438 HeapFree(GetProcessHeap(),0,This->itemName);
439 HeapFree(GetProcessHeap(),0,This->itemDelimiter);
440 HeapFree(GetProcessHeap(),0,This);
445 /******************************************************************************
446 * ItemMoniker_BindToObject
447 ******************************************************************************/
448 HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface,
454 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
457 IID refid=IID_IOleItemContainer;
458 IOleItemContainer *poic=0;
460 TRACE("(%p,%p,%p,%s,%p)\n",iface,pbc,pmkToLeft,debugstr_guid(riid),ppvResult);
470 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&refid,(void**)&poic);
474 res=IOleItemContainer_GetObject(poic,This->itemName,BINDSPEED_MODERATE,pbc,riid,ppvResult);
476 IOleItemContainer_Release(poic);
482 /******************************************************************************
483 * ItemMoniker_BindToStorage
484 ******************************************************************************/
485 HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker* iface,
491 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
494 IOleItemContainer *poic=0;
496 TRACE("(%p,%p,%p,%s,%p)\n",iface,pbc,pmkToLeft,debugstr_guid(riid),ppvResult);
503 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic);
507 res=IOleItemContainer_GetObjectStorage(poic,This->itemName,pbc,riid,ppvResult);
509 IOleItemContainer_Release(poic);
515 /******************************************************************************
517 ******************************************************************************/
518 HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface,
520 DWORD dwReduceHowFar,
521 IMoniker** ppmkToLeft,
522 IMoniker** ppmkReduced)
524 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
526 if (ppmkReduced==NULL)
529 ItemMonikerImpl_AddRef(iface);
533 return MK_S_REDUCED_TO_SELF;
535 /******************************************************************************
536 * ItemMoniker_ComposeWith
537 ******************************************************************************/
538 HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface,
540 BOOL fOnlyIfNotGeneric,
541 IMoniker** ppmkComposite)
545 IEnumMoniker* penumMk=0;
546 IMoniker *pmostLeftMk=0;
547 IMoniker* tempMkComposite=0;
549 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
551 if ((ppmkComposite==NULL)||(pmkRight==NULL))
556 IMoniker_IsSystemMoniker(pmkRight,&mkSys);
558 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
559 if(mkSys==MKSYS_ANTIMONIKER)
563 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
564 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
566 if(mkSys==MKSYS_GENERICCOMPOSITE){
568 res=IMoniker_Enum(pmkRight,TRUE,&penumMk);
573 res=IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL);
575 IMoniker_IsSystemMoniker(pmostLeftMk,&mkSys2);
577 if(mkSys2==MKSYS_ANTIMONIKER){
579 IMoniker_Release(pmostLeftMk);
581 tempMkComposite=iface;
582 IMoniker_AddRef(iface);
584 while(IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL)==S_OK){
586 res=CreateGenericComposite(tempMkComposite,pmostLeftMk,ppmkComposite);
588 IMoniker_Release(tempMkComposite);
589 IMoniker_Release(pmostLeftMk);
591 tempMkComposite=*ppmkComposite;
592 IMoniker_AddRef(tempMkComposite);
597 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
599 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
600 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
601 a NULL moniker and a return value of MK_E_NEEDGENERIC */
603 if (!fOnlyIfNotGeneric)
604 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
607 return MK_E_NEEDGENERIC;
610 /******************************************************************************
612 ******************************************************************************/
613 HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
615 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
617 if (ppenumMoniker == NULL)
620 *ppenumMoniker = NULL;
625 /******************************************************************************
626 * ItemMoniker_IsEqual
627 ******************************************************************************/
628 HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
632 LPOLESTR dispName1,dispName2;
634 HRESULT res = S_FALSE;
636 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
638 if (!pmkOtherMoniker) return S_FALSE;
641 /* check if both are ItemMoniker */
642 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker,&clsid))) return S_FALSE;
643 if(!IsEqualCLSID(&clsid,&CLSID_ItemMoniker)) return S_FALSE;
645 /* check if both displaynames are the same */
646 if(SUCCEEDED ((res = CreateBindCtx(0,&bind)))) {
647 if(SUCCEEDED (IMoniker_GetDisplayName(iface,bind,NULL,&dispName1))) {
648 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&dispName2))) {
649 if(lstrcmpW(dispName1,dispName2)==0) res = S_OK;
650 CoTaskMemFree(dispName2);
652 CoTaskMemFree(dispName1);
658 /******************************************************************************
660 ******************************************************************************/
661 HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
663 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
665 int h = 0,i,skip,len;
672 val = This->itemName;
676 for (i = len ; i > 0; i--) {
677 h = (h * 37) + val[off++];
680 /* only sample some characters */
682 for (i = len ; i > 0; i -= skip, off += skip) {
683 h = (h * 39) + val[off];
692 /******************************************************************************
693 * ItemMoniker_IsRunning
694 ******************************************************************************/
695 HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface,
698 IMoniker* pmkNewlyRunning)
700 IRunningObjectTable* rot;
702 IOleItemContainer *poic=0;
703 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
705 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
707 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
708 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
710 if ((pmkNewlyRunning!=NULL)&&(IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK))
716 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
721 res = IRunningObjectTable_IsRunning(rot,iface);
723 IRunningObjectTable_Release(rot);
727 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
728 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
729 /* passing the string contained within this moniker. */
731 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic);
735 res=IOleItemContainer_IsRunning(poic,This->itemName);
737 IOleItemContainer_Release(poic);
744 /******************************************************************************
745 * ItemMoniker_GetTimeOfLastChange
746 ******************************************************************************/
747 HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
752 IRunningObjectTable* rot;
754 IMoniker *compositeMk;
756 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pItemTime);
761 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
764 return MK_E_NOTBINDABLE;
767 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
768 /* the time of last change. If the object is not in the ROT, the method calls */
769 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
771 res=CreateGenericComposite(pmkToLeft,iface,&compositeMk);
773 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
775 if (IRunningObjectTable_GetTimeOfLastChange(rot,compositeMk,pItemTime)!=S_OK)
777 res=IMoniker_GetTimeOfLastChange(pmkToLeft,pbc,NULL,pItemTime);
779 IMoniker_Release(compositeMk);
785 /******************************************************************************
786 * ItemMoniker_Inverse
787 ******************************************************************************/
788 HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
790 TRACE("(%p,%p)\n",iface,ppmk);
795 return CreateAntiMoniker(ppmk);
798 /******************************************************************************
799 * ItemMoniker_CommonPrefixWith
800 ******************************************************************************/
801 HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
805 TRACE("(%p,%p)\n", pmkOther, ppmkPrefix);
807 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
808 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
809 /* to this moniker and returns MK_S_US */
811 if((mkSys==MKSYS_ITEMMONIKER) && (IMoniker_IsEqual(iface,pmkOther)==S_OK) ){
815 IMoniker_AddRef(iface);
820 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
821 /* the case where the other moniker is a generic composite. */
822 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
825 /******************************************************************************
826 * ItemMoniker_RelativePathTo
827 ******************************************************************************/
828 HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
830 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
832 if (ppmkRelPath==NULL)
837 return MK_E_NOTBINDABLE;
840 /******************************************************************************
841 * ItemMoniker_GetDisplayName
842 ******************************************************************************/
843 HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface,
846 LPOLESTR *ppszDisplayName)
848 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
850 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
852 if (ppszDisplayName==NULL)
855 if (pmkToLeft!=NULL){
859 *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(lstrlenW(This->itemDelimiter)+lstrlenW(This->itemName)+1));
861 if (*ppszDisplayName==NULL)
862 return E_OUTOFMEMORY;
864 lstrcpyW(*ppszDisplayName,This->itemDelimiter);
865 lstrcatW(*ppszDisplayName,This->itemName);
867 TRACE("-- %s\n", debugstr_w(*ppszDisplayName));
872 /******************************************************************************
873 * ItemMoniker_ParseDisplayName
874 ******************************************************************************/
875 HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker* iface,
878 LPOLESTR pszDisplayName,
882 IOleItemContainer* poic=0;
883 IParseDisplayName* ppdn=0;
884 LPOLESTR displayName;
886 ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
888 TRACE("%s\n", debugstr_w(pszDisplayName));
890 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
896 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
897 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
898 /* name to IParseDisplayName::ParseDisplayName */
899 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic);
903 res=IOleItemContainer_GetObject(poic,This->itemName,BINDSPEED_MODERATE,pbc,&IID_IParseDisplayName,(void**)&ppdn);
905 res=IMoniker_GetDisplayName(iface,pbc,NULL,&displayName);
907 res=IParseDisplayName_ParseDisplayName(ppdn,pbc,displayName,pchEaten,ppmkOut);
909 IOleItemContainer_Release(poic);
910 IParseDisplayName_Release(ppdn);
916 /******************************************************************************
917 * ItemMoniker_IsSystemMoniker
918 ******************************************************************************/
919 HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
921 TRACE("(%p,%p)\n",iface,pwdMksys);
926 (*pwdMksys)=MKSYS_ITEMMONIKER;
931 /*******************************************************************************
932 * ItemMonikerIROTData_QueryInterface
933 *******************************************************************************/
934 HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
937 IMoniker *This = impl_from_IROTData(iface);
939 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
941 return ItemMonikerImpl_QueryInterface(This, riid, ppvObject);
944 /***********************************************************************
945 * ItemMonikerIROTData_AddRef
947 ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData *iface)
949 IMoniker *This = impl_from_IROTData(iface);
951 TRACE("(%p)\n",iface);
953 return ItemMonikerImpl_AddRef(This);
956 /***********************************************************************
957 * ItemMonikerIROTData_Release
959 ULONG WINAPI ItemMonikerROTDataImpl_Release(IROTData* iface)
961 IMoniker *This = impl_from_IROTData(iface);
963 TRACE("(%p)\n",iface);
965 return ItemMonikerImpl_Release(This);
968 /******************************************************************************
969 * ItemMonikerIROTData_GetComparaisonData
970 ******************************************************************************/
971 HRESULT WINAPI ItemMonikerROTDataImpl_GetComparisonData(IROTData* iface,
976 IMoniker *This = impl_from_IROTData(iface);
977 ItemMonikerImpl *This1 = (ItemMonikerImpl *)This;
978 int len = (strlenW(This1->itemName)+1);
981 LPWSTR pszItemDelimiter;
983 TRACE("(%p, %lu, %p)\n", pbData, cbMax, pcbData);
985 *pcbData = sizeof(CLSID) + sizeof(WCHAR) + len * sizeof(WCHAR);
986 if (cbMax < *pcbData)
987 return E_OUTOFMEMORY;
990 memcpy(pbData, &CLSID_ItemMoniker, sizeof(CLSID));
991 /* write delimiter */
992 pszItemDelimiter = (LPWSTR)(pbData+sizeof(CLSID));
993 *pszItemDelimiter = *This1->itemDelimiter;
995 pszItemName = pszItemDelimiter + 1;
996 for (i = 0; i < len; i++)
997 pszItemName[i] = toupperW(This1->itemName[i]);
1002 /******************************************************************************
1003 * CreateItemMoniker [OLE32.@]
1004 ******************************************************************************/
1005 HRESULT WINAPI CreateItemMoniker(LPCOLESTR lpszDelim,LPCOLESTR lpszItem, LPMONIKER * ppmk)
1007 ItemMonikerImpl* newItemMoniker;
1010 TRACE("(%s,%s,%p)\n",debugstr_w(lpszDelim),debugstr_w(lpszItem),ppmk);
1012 newItemMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl));
1014 if (!newItemMoniker)
1015 return STG_E_INSUFFICIENTMEMORY;
1017 hr = ItemMonikerImpl_Construct(newItemMoniker,lpszDelim,lpszItem);
1021 HeapFree(GetProcessHeap(),0,newItemMoniker);
1025 return ItemMonikerImpl_QueryInterface((IMoniker*)newItemMoniker,&IID_IMoniker,(void**)ppmk);
1028 static HRESULT WINAPI ItemMonikerCF_QueryInterface(LPCLASSFACTORY iface,
1029 REFIID riid, LPVOID *ppv)
1032 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
1035 IUnknown_AddRef(iface);
1038 return E_NOINTERFACE;
1041 static ULONG WINAPI ItemMonikerCF_AddRef(LPCLASSFACTORY iface)
1043 return 2; /* non-heap based object */
1046 static ULONG WINAPI ItemMonikerCF_Release(LPCLASSFACTORY iface)
1048 return 1; /* non-heap based object */
1051 static HRESULT WINAPI ItemMonikerCF_CreateInstance(LPCLASSFACTORY iface,
1052 LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
1054 ItemMonikerImpl* newItemMoniker;
1056 static const WCHAR wszEmpty[] = { 0 };
1058 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);
1063 return CLASS_E_NOAGGREGATION;
1065 newItemMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl));
1066 if (!newItemMoniker)
1067 return E_OUTOFMEMORY;
1069 hr = ItemMonikerImpl_Construct(newItemMoniker, wszEmpty, wszEmpty);
1072 hr = ItemMonikerImpl_QueryInterface((IMoniker*)newItemMoniker, riid, ppv);
1074 HeapFree(GetProcessHeap(),0,newItemMoniker);
1079 static HRESULT WINAPI ItemMonikerCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
1081 FIXME("(%d), stub!\n",fLock);
1085 static const IClassFactoryVtbl ItemMonikerCFVtbl =
1087 ItemMonikerCF_QueryInterface,
1088 ItemMonikerCF_AddRef,
1089 ItemMonikerCF_Release,
1090 ItemMonikerCF_CreateInstance,
1091 ItemMonikerCF_LockServer
1093 static const IClassFactoryVtbl *ItemMonikerCF = &ItemMonikerCFVtbl;
1095 HRESULT ItemMonikerCF_Create(REFIID riid, LPVOID *ppv)
1097 return IClassFactory_QueryInterface((IClassFactory *)&ItemMonikerCF, riid, ppv);