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 ***************************************************************************************/
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
29 #include "wine/debug.h"
31 #include "wine/unicode.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
36 const CLSID CLSID_ItemMoniker
= {
37 0x304, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
40 /* ItemMoniker data structure */
41 typedef struct ItemMonikerImpl
{
43 ICOM_VTABLE(IMoniker
)* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
45 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
46 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
48 ICOM_VTABLE(IROTData
)* lpvtbl2
; /* VTable relative to the IROTData interface.*/
50 ULONG ref
; /* reference counter for this object */
52 LPOLESTR itemName
; /* item name identified by this ItemMoniker */
54 LPOLESTR itemDelimiter
; /* Delimiter string */
58 /********************************************************************************/
59 /* ItemMoniker prototype functions : */
61 /* IUnknown prototype functions */
62 static HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
);
63 static ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
);
64 static ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
);
66 /* IPersist prototype functions */
67 static HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
, CLSID
*pClassID
);
69 /* IPersistStream prototype functions */
70 static HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
);
71 static HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
, IStream
* pStm
);
72 static HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
);
73 static HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
);
75 /* IMoniker prototype functions */
76 static HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
77 static HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
78 static HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,IBindCtx
* pbc
, DWORD dwReduceHowFar
,IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
);
79 static HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,IMoniker
* pmkRight
,BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
);
80 static HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
);
81 static HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
);
82 static HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
);
83 static HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, IMoniker
* pmkNewlyRunning
);
84 static HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
, FILETIME
* pItemTime
);
85 static HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
);
86 static HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
, IMoniker
** ppmkPrefix
);
87 static HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
);
88 static HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
);
89 static HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
);
90 static HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
);
92 /* Local function used by ItemMoniker implementation */
93 HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* iface
, LPCOLESTR lpszDelim
,LPCOLESTR lpszPathName
);
94 HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* iface
);
96 /********************************************************************************/
97 /* IROTData prototype functions */
99 /* IUnknown prototype functions */
100 static HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
* iface
,REFIID riid
,VOID
** ppvObject
);
101 static ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
* iface
);
102 static ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
);
104 /* IROTData prototype function */
105 static HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,BYTE
* pbData
,ULONG cbMax
,ULONG
* pcbData
);
107 /********************************************************************************/
108 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
109 /* IPersistStream and IMoniker functions. */
110 static ICOM_VTABLE(IMoniker
) VT_ItemMonikerImpl
=
112 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
113 ItemMonikerImpl_QueryInterface
,
114 ItemMonikerImpl_AddRef
,
115 ItemMonikerImpl_Release
,
116 ItemMonikerImpl_GetClassID
,
117 ItemMonikerImpl_IsDirty
,
118 ItemMonikerImpl_Load
,
119 ItemMonikerImpl_Save
,
120 ItemMonikerImpl_GetSizeMax
,
121 ItemMonikerImpl_BindToObject
,
122 ItemMonikerImpl_BindToStorage
,
123 ItemMonikerImpl_Reduce
,
124 ItemMonikerImpl_ComposeWith
,
125 ItemMonikerImpl_Enum
,
126 ItemMonikerImpl_IsEqual
,
127 ItemMonikerImpl_Hash
,
128 ItemMonikerImpl_IsRunning
,
129 ItemMonikerImpl_GetTimeOfLastChange
,
130 ItemMonikerImpl_Inverse
,
131 ItemMonikerImpl_CommonPrefixWith
,
132 ItemMonikerImpl_RelativePathTo
,
133 ItemMonikerImpl_GetDisplayName
,
134 ItemMonikerImpl_ParseDisplayName
,
135 ItemMonikerImpl_IsSystemMoniker
138 /********************************************************************************/
139 /* Virtual function table for the IROTData class. */
140 static ICOM_VTABLE(IROTData
) VT_ROTDataImpl
=
142 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
143 ItemMonikerROTDataImpl_QueryInterface
,
144 ItemMonikerROTDataImpl_AddRef
,
145 ItemMonikerROTDataImpl_Release
,
146 ItemMonikerROTDataImpl_GetComparaisonData
149 /*******************************************************************************
150 * ItemMoniker_QueryInterface
151 *******************************************************************************/
152 HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
154 ICOM_THIS(ItemMonikerImpl
,iface
);
156 TRACE("(%p,%p,%p)\n",This
,riid
,ppvObject
);
158 /* Perform a sanity check on the parameters.*/
159 if ( (This
==0) || (ppvObject
==0) )
162 /* Initialize the return parameter */
165 /* Compare the riid with the interface IDs implemented by this object.*/
166 if (IsEqualIID(&IID_IUnknown
, riid
) ||
167 IsEqualIID(&IID_IPersist
, riid
) ||
168 IsEqualIID(&IID_IPersistStream
, riid
) ||
169 IsEqualIID(&IID_IMoniker
, riid
)
173 else if (IsEqualIID(&IID_IROTData
, riid
))
174 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
176 /* Check that we obtained an interface.*/
178 return E_NOINTERFACE
;
180 /* Query Interface always increases the reference count by one when it is successful */
181 ItemMonikerImpl_AddRef(iface
);
186 /******************************************************************************
188 ******************************************************************************/
189 ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
)
191 ICOM_THIS(ItemMonikerImpl
,iface
);
193 TRACE("(%p)\n",This
);
195 return ++(This
->ref
);
198 /******************************************************************************
199 * ItemMoniker_Release
200 ******************************************************************************/
201 ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
)
203 ICOM_THIS(ItemMonikerImpl
,iface
);
205 TRACE("(%p)\n",This
);
209 /* destroy the object if there's no more reference on it */
212 ItemMonikerImpl_Destroy(This
);
219 /******************************************************************************
220 * ItemMoniker_GetClassID
221 ******************************************************************************/
222 HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
224 TRACE("(%p,%p),stub!\n",iface
,pClassID
);
229 *pClassID
= CLSID_ItemMoniker
;
234 /******************************************************************************
235 * ItemMoniker_IsDirty
236 ******************************************************************************/
237 HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
)
239 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
240 method in the OLE-provided moniker interfaces always return S_FALSE because
241 their internal state never changes. */
243 TRACE("(%p)\n",iface
);
248 /******************************************************************************
250 ******************************************************************************/
251 HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
254 ICOM_THIS(ItemMonikerImpl
,iface
);
256 DWORD delimiterLength
,nameLength
,lenW
;
257 CHAR
*itemNameA
,*itemDelimiterA
;
260 /* for more details about data read by this function see coments of ItemMonikerImpl_Save function */
262 /* read item delimiter string length + 1 */
263 res
=IStream_Read(pStm
,&delimiterLength
,sizeof(DWORD
),&bread
);
264 if (bread
!= sizeof(DWORD
))
267 /* read item delimiter string */
268 if (!(itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
)))
269 return E_OUTOFMEMORY
;
270 res
=IStream_Read(pStm
,itemDelimiterA
,delimiterLength
,&bread
);
271 if (bread
!= delimiterLength
)
273 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
277 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, NULL
, 0 );
278 This
->itemDelimiter
=HeapReAlloc(GetProcessHeap(),0,This
->itemDelimiter
,lenW
*sizeof(WCHAR
));
279 if (!This
->itemDelimiter
)
281 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
282 return E_OUTOFMEMORY
;
284 MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, This
->itemDelimiter
, lenW
);
285 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
287 /* read item name string length + 1*/
288 res
=IStream_Read(pStm
,&nameLength
,sizeof(DWORD
),&bread
);
289 if (bread
!= sizeof(DWORD
))
292 /* read item name string */
293 if (!(itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
)))
294 return E_OUTOFMEMORY
;
295 res
=IStream_Read(pStm
,itemNameA
,nameLength
,&bread
);
296 if (bread
!= nameLength
)
298 HeapFree( GetProcessHeap(), 0, itemNameA
);
302 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, NULL
, 0 );
303 This
->itemName
=HeapReAlloc(GetProcessHeap(),0,This
->itemName
,lenW
*sizeof(WCHAR
));
306 HeapFree( GetProcessHeap(), 0, itemNameA
);
307 return E_OUTOFMEMORY
;
309 MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, This
->itemName
, lenW
);
310 HeapFree( GetProcessHeap(), 0, itemNameA
);
315 /******************************************************************************
317 ******************************************************************************/
318 HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
,
319 IStream
* pStm
,/* pointer to the stream where the object is to be saved */
320 BOOL fClearDirty
)/* Specifies whether to clear the dirty flag */
322 ICOM_THIS(ItemMonikerImpl
,iface
);
324 CHAR
*itemNameA
,*itemDelimiterA
;
326 /* data writen by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
327 /* 2) String (type A): item delimiter string ('\0' included) */
328 /* 3) DWORD : size of item name string ('\0' included) */
329 /* 4) String (type A): item name string ('\0' included) */
331 DWORD nameLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, NULL
, 0, NULL
, NULL
);
332 DWORD delimiterLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, NULL
, 0, NULL
, NULL
);
333 itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
);
334 itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
);
335 WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, itemNameA
, nameLength
, NULL
, NULL
);
336 WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, itemDelimiterA
, delimiterLength
, NULL
, NULL
);
338 res
=IStream_Write(pStm
,&delimiterLength
,sizeof(DWORD
),NULL
);
339 res
=IStream_Write(pStm
,itemDelimiterA
,delimiterLength
* sizeof(CHAR
),NULL
);
340 res
=IStream_Write(pStm
,&nameLength
,sizeof(DWORD
),NULL
);
341 res
=IStream_Write(pStm
,itemNameA
,nameLength
* sizeof(CHAR
),NULL
);
346 /******************************************************************************
347 * ItemMoniker_GetSizeMax
348 ******************************************************************************/
349 HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
,
350 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
352 ICOM_THIS(ItemMonikerImpl
,iface
);
353 DWORD delimiterLength
=lstrlenW(This
->itemDelimiter
)+1;
354 DWORD nameLength
=lstrlenW(This
->itemName
)+1;
356 TRACE("(%p,%p)\n",iface
,pcbSize
);
361 /* for more details see ItemMonikerImpl_Save coments */
363 pcbSize
->s
.LowPart
= sizeof(DWORD
) + /* DWORD which contains delimiter length */
364 delimiterLength
+ /* item delimiter string */
365 sizeof(DWORD
) + /* DWORD which contains item name length */
366 nameLength
+ /* item name string */
367 34; /* this constant was added ! because when I tested this function it usually */
368 /* returns 34 bytes more than the number of bytes used by IMoniker::Save function */
369 pcbSize
->s
.HighPart
=0;
374 /******************************************************************************
375 * ItemMoniker_Construct (local function)
376 *******************************************************************************/
377 HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* This
, LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
)
380 int sizeStr1
=lstrlenW(lpszItem
), sizeStr2
;
381 static const OLECHAR emptystr
[1];
384 TRACE("(%p,%p)\n",This
,lpszItem
);
386 /* Initialize the virtual fgunction table. */
387 This
->lpvtbl1
= &VT_ItemMonikerImpl
;
388 This
->lpvtbl2
= &VT_ROTDataImpl
;
391 This
->itemName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr1
+1));
393 return E_OUTOFMEMORY
;
394 lstrcpyW(This
->itemName
,lpszItem
);
397 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
399 delim
= lpszDelim
? lpszDelim
: emptystr
;
401 sizeStr2
=lstrlenW(delim
);
402 This
->itemDelimiter
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr2
+1));
403 if (!This
->itemDelimiter
) {
404 HeapFree(GetProcessHeap(),0,This
->itemName
);
405 return E_OUTOFMEMORY
;
407 lstrcpyW(This
->itemDelimiter
,delim
);
411 /******************************************************************************
412 * ItemMoniker_Destroy (local function)
413 *******************************************************************************/
414 HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* This
)
416 TRACE("(%p)\n",This
);
419 HeapFree(GetProcessHeap(),0,This
->itemName
);
421 if (This
->itemDelimiter
)
422 HeapFree(GetProcessHeap(),0,This
->itemDelimiter
);
424 HeapFree(GetProcessHeap(),0,This
);
429 /******************************************************************************
430 * ItemMoniker_BindToObject
431 ******************************************************************************/
432 HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,
438 ICOM_THIS(ItemMonikerImpl
,iface
);
441 IID refid
=IID_IOleItemContainer
;
442 IOleItemContainer
*poic
=0;
444 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
454 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&refid
,(void**)&poic
);
458 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,riid
,ppvResult
);
460 IOleItemContainer_Release(poic
);
466 /******************************************************************************
467 * ItemMoniker_BindToStorage
468 ******************************************************************************/
469 HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,
475 ICOM_THIS(ItemMonikerImpl
,iface
);
478 IOleItemContainer
*poic
=0;
480 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
487 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
491 res
=IOleItemContainer_GetObjectStorage(poic
,This
->itemName
,pbc
,riid
,ppvResult
);
493 IOleItemContainer_Release(poic
);
499 /******************************************************************************
501 ******************************************************************************/
502 HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,
504 DWORD dwReduceHowFar
,
505 IMoniker
** ppmkToLeft
,
506 IMoniker
** ppmkReduced
)
508 TRACE("(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
510 if (ppmkReduced
==NULL
)
513 ItemMonikerImpl_AddRef(iface
);
517 return MK_S_REDUCED_TO_SELF
;
519 /******************************************************************************
520 * ItemMoniker_ComposeWith
521 ******************************************************************************/
522 HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,
524 BOOL fOnlyIfNotGeneric
,
525 IMoniker
** ppmkComposite
)
529 IEnumMoniker
* penumMk
=0;
530 IMoniker
*pmostLeftMk
=0;
531 IMoniker
* tempMkComposite
=0;
533 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
535 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
540 IMoniker_IsSystemMoniker(pmkRight
,&mkSys
);
542 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
543 if(mkSys
==MKSYS_ANTIMONIKER
)
547 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
548 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
550 if(mkSys
==MKSYS_GENERICCOMPOSITE
){
552 res
=IMoniker_Enum(pmkRight
,TRUE
,&penumMk
);
557 res
=IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
);
559 IMoniker_IsSystemMoniker(pmostLeftMk
,&mkSys2
);
561 if(mkSys2
==MKSYS_ANTIMONIKER
){
563 IMoniker_Release(pmostLeftMk
);
565 tempMkComposite
=iface
;
566 IMoniker_AddRef(iface
);
568 while(IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
)==S_OK
){
570 res
=CreateGenericComposite(tempMkComposite
,pmostLeftMk
,ppmkComposite
);
572 IMoniker_Release(tempMkComposite
);
573 IMoniker_Release(pmostLeftMk
);
575 tempMkComposite
=*ppmkComposite
;
576 IMoniker_AddRef(tempMkComposite
);
581 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
583 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
584 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
585 a NULL moniker and a return value of MK_E_NEEDGENERIC */
587 if (!fOnlyIfNotGeneric
)
588 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
591 return MK_E_NEEDGENERIC
;
594 /******************************************************************************
596 ******************************************************************************/
597 HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
599 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
601 if (ppenumMoniker
== NULL
)
604 *ppenumMoniker
= NULL
;
609 /******************************************************************************
610 * ItemMoniker_IsEqual
611 ******************************************************************************/
612 HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
616 LPOLESTR dispName1
,dispName2
;
618 HRESULT res
= S_FALSE
;
620 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
622 if (!pmkOtherMoniker
) return S_FALSE
;
625 /* check if both are ItemMoniker */
626 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker
,&clsid
))) return S_FALSE
;
627 if(!IsEqualCLSID(&clsid
,&CLSID_ItemMoniker
)) return S_FALSE
;
629 /* check if both displaynames are the same */
630 if(SUCCEEDED ((res
= CreateBindCtx(0,&bind
)))) {
631 if(SUCCEEDED (IMoniker_GetDisplayName(iface
,bind
,NULL
,&dispName1
))) {
632 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&dispName2
))) {
633 if(lstrcmpW(dispName1
,dispName2
)==0) res
= S_OK
;
634 CoTaskMemFree(dispName2
);
636 CoTaskMemFree(dispName1
);
642 /******************************************************************************
644 ******************************************************************************/
645 HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
647 ICOM_THIS(ItemMonikerImpl
,iface
);
649 int h
= 0,i
,skip
,len
;
656 val
= This
->itemName
;
660 for (i
= len
; i
> 0; i
--) {
661 h
= (h
* 37) + val
[off
++];
664 /* only sample some characters */
666 for (i
= len
; i
> 0; i
-= skip
, off
+= skip
) {
667 h
= (h
* 39) + val
[off
];
676 /******************************************************************************
677 * ItemMoniker_IsRunning
678 ******************************************************************************/
679 HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,
682 IMoniker
* pmkNewlyRunning
)
684 IRunningObjectTable
* rot
;
686 IOleItemContainer
*poic
=0;
687 ICOM_THIS(ItemMonikerImpl
,iface
);
689 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
691 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
692 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
694 if ((pmkNewlyRunning
!=NULL
)&&(IMoniker_IsEqual(pmkNewlyRunning
,iface
)==S_OK
))
700 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
705 res
= IRunningObjectTable_IsRunning(rot
,iface
);
707 IRunningObjectTable_Release(rot
);
711 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
712 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
713 /* passing the string contained within this moniker. */
715 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
719 res
=IOleItemContainer_IsRunning(poic
,This
->itemName
);
721 IOleItemContainer_Release(poic
);
728 /******************************************************************************
729 * ItemMoniker_GetTimeOfLastChange
730 ******************************************************************************/
731 HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
736 IRunningObjectTable
* rot
;
738 IMoniker
*compositeMk
;
740 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pItemTime
);
745 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
748 return MK_E_NOTBINDABLE
;
751 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
752 /* the time of last change. If the object is not in the ROT, the method calls */
753 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
755 res
=CreateGenericComposite(pmkToLeft
,iface
,&compositeMk
);
757 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
759 if (IRunningObjectTable_GetTimeOfLastChange(rot
,compositeMk
,pItemTime
)!=S_OK
)
761 res
=IMoniker_GetTimeOfLastChange(pmkToLeft
,pbc
,NULL
,pItemTime
);
763 IMoniker_Release(compositeMk
);
769 /******************************************************************************
770 * ItemMoniker_Inverse
771 ******************************************************************************/
772 HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
774 TRACE("(%p,%p)\n",iface
,ppmk
);
779 return CreateAntiMoniker(ppmk
);
782 /******************************************************************************
783 * ItemMoniker_CommonPrefixWith
784 ******************************************************************************/
785 HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
788 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
789 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
790 /* to this moniker and returns MK_S_US */
792 if((mkSys
==MKSYS_ITEMMONIKER
) && (IMoniker_IsEqual(iface
,pmkOther
)==S_OK
) ){
796 IMoniker_AddRef(iface
);
801 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
802 /* the case where the other moniker is a generic composite. */
803 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
806 /******************************************************************************
807 * ItemMoniker_RelativePathTo
808 ******************************************************************************/
809 HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
811 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
813 if (ppmkRelPath
==NULL
)
818 return MK_E_NOTBINDABLE
;
821 /******************************************************************************
822 * ItemMoniker_GetDisplayName
823 ******************************************************************************/
824 HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,
827 LPOLESTR
*ppszDisplayName
)
829 ICOM_THIS(ItemMonikerImpl
,iface
);
831 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
833 if (ppszDisplayName
==NULL
)
836 if (pmkToLeft
!=NULL
){
840 *ppszDisplayName
=CoTaskMemAlloc(sizeof(WCHAR
)*(lstrlenW(This
->itemDelimiter
)+lstrlenW(This
->itemName
)+1));
842 if (*ppszDisplayName
==NULL
)
843 return E_OUTOFMEMORY
;
845 lstrcpyW(*ppszDisplayName
,This
->itemDelimiter
);
846 lstrcatW(*ppszDisplayName
,This
->itemName
);
851 /******************************************************************************
852 * ItemMoniker_ParseDisplayName
853 ******************************************************************************/
854 HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,
857 LPOLESTR pszDisplayName
,
861 IOleItemContainer
* poic
=0;
862 IParseDisplayName
* ppdn
=0;
863 LPOLESTR displayName
;
865 ICOM_THIS(ItemMonikerImpl
,iface
);
867 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
873 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
874 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
875 /* name to IParseDisplayName::ParseDisplayName */
876 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
880 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,&IID_IParseDisplayName
,(void**)&ppdn
);
882 res
=IMoniker_GetDisplayName(iface
,pbc
,NULL
,&displayName
);
884 res
=IParseDisplayName_ParseDisplayName(ppdn
,pbc
,displayName
,pchEaten
,ppmkOut
);
886 IOleItemContainer_Release(poic
);
887 IParseDisplayName_Release(ppdn
);
893 /******************************************************************************
894 * ItemMoniker_IsSystemMoniker
895 ******************************************************************************/
896 HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
898 TRACE("(%p,%p)\n",iface
,pwdMksys
);
903 (*pwdMksys
)=MKSYS_ITEMMONIKER
;
908 /*******************************************************************************
909 * ItemMonikerIROTData_QueryInterface
910 *******************************************************************************/
911 HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
914 ICOM_THIS_From_IROTData(IMoniker
, iface
);
916 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
918 return ItemMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
921 /***********************************************************************
922 * ItemMonikerIROTData_AddRef
924 ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
*iface
)
926 ICOM_THIS_From_IROTData(IMoniker
, iface
);
928 TRACE("(%p)\n",iface
);
930 return ItemMonikerImpl_AddRef(This
);
933 /***********************************************************************
934 * ItemMonikerIROTData_Release
936 ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
)
938 ICOM_THIS_From_IROTData(IMoniker
, iface
);
940 TRACE("(%p)\n",iface
);
942 return ItemMonikerImpl_Release(This
);
945 /******************************************************************************
946 * ItemMonikerIROTData_GetComparaisonData
947 ******************************************************************************/
948 HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,
957 /******************************************************************************
958 * CreateItemMoniker16 [OLE2.28]
959 ******************************************************************************/
960 HRESULT WINAPI
CreateItemMoniker16(LPCOLESTR16 lpszDelim
,LPCOLESTR lpszItem
,LPMONIKER
* ppmk
)
963 FIXME("(%s,%p),stub!\n",lpszDelim
,ppmk
);
968 /******************************************************************************
969 * CreateItemMoniker [OLE32.58]
970 ******************************************************************************/
971 HRESULT WINAPI
CreateItemMoniker(LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
, LPMONIKER
* ppmk
)
973 ItemMonikerImpl
* newItemMoniker
= 0;
975 IID riid
=IID_IMoniker
;
977 TRACE("(%p,%p,%p)\n",lpszDelim
,lpszItem
,ppmk
);
979 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
981 if (newItemMoniker
== 0)
982 return STG_E_INSUFFICIENTMEMORY
;
984 hr
= ItemMonikerImpl_Construct(newItemMoniker
,lpszDelim
,lpszItem
);
988 HeapFree(GetProcessHeap(),0,newItemMoniker
);
992 return ItemMonikerImpl_QueryInterface((IMoniker
*)newItemMoniker
,&riid
,(void**)ppmk
);