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 ***************************************************************************************/
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
31 #include "wine/debug.h"
33 #include "wine/unicode.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
38 const CLSID CLSID_ItemMoniker
= {
39 0x304, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
42 /* ItemMoniker data structure */
43 typedef struct ItemMonikerImpl
{
45 ICOM_VTABLE(IMoniker
)* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
47 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
48 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
50 ICOM_VTABLE(IROTData
)* lpvtbl2
; /* VTable relative to the IROTData interface.*/
52 ULONG ref
; /* reference counter for this object */
54 LPOLESTR itemName
; /* item name identified by this ItemMoniker */
56 LPOLESTR itemDelimiter
; /* Delimiter string */
60 /********************************************************************************/
61 /* ItemMoniker prototype functions : */
63 /* IUnknown prototype functions */
64 static HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
);
65 static ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
);
66 static ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
);
68 /* IPersist prototype functions */
69 static HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
, CLSID
*pClassID
);
71 /* IPersistStream prototype functions */
72 static HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
);
73 static HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
, IStream
* pStm
);
74 static HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
);
75 static HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
);
77 /* IMoniker prototype functions */
78 static HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
79 static HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
80 static HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,IBindCtx
* pbc
, DWORD dwReduceHowFar
,IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
);
81 static HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,IMoniker
* pmkRight
,BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
);
82 static HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
);
83 static HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
);
84 static HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
);
85 static HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, IMoniker
* pmkNewlyRunning
);
86 static HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
, FILETIME
* pItemTime
);
87 static HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
);
88 static HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
, IMoniker
** ppmkPrefix
);
89 static HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
);
90 static HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
);
91 static HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
);
92 static HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
);
94 /* Local function used by ItemMoniker implementation */
95 HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* iface
, LPCOLESTR lpszDelim
,LPCOLESTR lpszPathName
);
96 HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* iface
);
98 /********************************************************************************/
99 /* IROTData prototype functions */
101 /* IUnknown prototype functions */
102 static HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
* iface
,REFIID riid
,VOID
** ppvObject
);
103 static ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
* iface
);
104 static ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
);
106 /* IROTData prototype function */
107 static HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,BYTE
* pbData
,ULONG cbMax
,ULONG
* pcbData
);
109 /********************************************************************************/
110 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
111 /* IPersistStream and IMoniker functions. */
112 static ICOM_VTABLE(IMoniker
) VT_ItemMonikerImpl
=
114 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
115 ItemMonikerImpl_QueryInterface
,
116 ItemMonikerImpl_AddRef
,
117 ItemMonikerImpl_Release
,
118 ItemMonikerImpl_GetClassID
,
119 ItemMonikerImpl_IsDirty
,
120 ItemMonikerImpl_Load
,
121 ItemMonikerImpl_Save
,
122 ItemMonikerImpl_GetSizeMax
,
123 ItemMonikerImpl_BindToObject
,
124 ItemMonikerImpl_BindToStorage
,
125 ItemMonikerImpl_Reduce
,
126 ItemMonikerImpl_ComposeWith
,
127 ItemMonikerImpl_Enum
,
128 ItemMonikerImpl_IsEqual
,
129 ItemMonikerImpl_Hash
,
130 ItemMonikerImpl_IsRunning
,
131 ItemMonikerImpl_GetTimeOfLastChange
,
132 ItemMonikerImpl_Inverse
,
133 ItemMonikerImpl_CommonPrefixWith
,
134 ItemMonikerImpl_RelativePathTo
,
135 ItemMonikerImpl_GetDisplayName
,
136 ItemMonikerImpl_ParseDisplayName
,
137 ItemMonikerImpl_IsSystemMoniker
140 /********************************************************************************/
141 /* Virtual function table for the IROTData class. */
142 static ICOM_VTABLE(IROTData
) VT_ROTDataImpl
=
144 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
145 ItemMonikerROTDataImpl_QueryInterface
,
146 ItemMonikerROTDataImpl_AddRef
,
147 ItemMonikerROTDataImpl_Release
,
148 ItemMonikerROTDataImpl_GetComparaisonData
151 /*******************************************************************************
152 * ItemMoniker_QueryInterface
153 *******************************************************************************/
154 HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
156 ICOM_THIS(ItemMonikerImpl
,iface
);
158 TRACE("(%p,%p,%p)\n",This
,riid
,ppvObject
);
160 /* Perform a sanity check on the parameters.*/
161 if ( (This
==0) || (ppvObject
==0) )
164 /* Initialize the return parameter */
167 /* Compare the riid with the interface IDs implemented by this object.*/
168 if (IsEqualIID(&IID_IUnknown
, riid
) ||
169 IsEqualIID(&IID_IPersist
, riid
) ||
170 IsEqualIID(&IID_IPersistStream
, riid
) ||
171 IsEqualIID(&IID_IMoniker
, riid
)
175 else if (IsEqualIID(&IID_IROTData
, riid
))
176 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
178 /* Check that we obtained an interface.*/
180 return E_NOINTERFACE
;
182 /* Query Interface always increases the reference count by one when it is successful */
183 ItemMonikerImpl_AddRef(iface
);
188 /******************************************************************************
190 ******************************************************************************/
191 ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
)
193 ICOM_THIS(ItemMonikerImpl
,iface
);
195 TRACE("(%p)\n",This
);
197 return ++(This
->ref
);
200 /******************************************************************************
201 * ItemMoniker_Release
202 ******************************************************************************/
203 ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
)
205 ICOM_THIS(ItemMonikerImpl
,iface
);
207 TRACE("(%p)\n",This
);
211 /* destroy the object if there's no more reference on it */
214 ItemMonikerImpl_Destroy(This
);
221 /******************************************************************************
222 * ItemMoniker_GetClassID
223 ******************************************************************************/
224 HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
226 TRACE("(%p,%p),stub!\n",iface
,pClassID
);
231 *pClassID
= CLSID_ItemMoniker
;
236 /******************************************************************************
237 * ItemMoniker_IsDirty
238 ******************************************************************************/
239 HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
)
241 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
242 method in the OLE-provided moniker interfaces always return S_FALSE because
243 their internal state never changes. */
245 TRACE("(%p)\n",iface
);
250 /******************************************************************************
252 ******************************************************************************/
253 HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
256 ICOM_THIS(ItemMonikerImpl
,iface
);
258 DWORD delimiterLength
,nameLength
,lenW
;
259 CHAR
*itemNameA
,*itemDelimiterA
;
262 /* for more details about data read by this function see coments of ItemMonikerImpl_Save function */
264 /* read item delimiter string length + 1 */
265 res
=IStream_Read(pStm
,&delimiterLength
,sizeof(DWORD
),&bread
);
266 if (bread
!= sizeof(DWORD
))
269 /* read item delimiter string */
270 if (!(itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
)))
271 return E_OUTOFMEMORY
;
272 res
=IStream_Read(pStm
,itemDelimiterA
,delimiterLength
,&bread
);
273 if (bread
!= delimiterLength
)
275 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
279 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, NULL
, 0 );
280 This
->itemDelimiter
=HeapReAlloc(GetProcessHeap(),0,This
->itemDelimiter
,lenW
*sizeof(WCHAR
));
281 if (!This
->itemDelimiter
)
283 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
284 return E_OUTOFMEMORY
;
286 MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, This
->itemDelimiter
, lenW
);
287 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
289 /* read item name string length + 1*/
290 res
=IStream_Read(pStm
,&nameLength
,sizeof(DWORD
),&bread
);
291 if (bread
!= sizeof(DWORD
))
294 /* read item name string */
295 if (!(itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
)))
296 return E_OUTOFMEMORY
;
297 res
=IStream_Read(pStm
,itemNameA
,nameLength
,&bread
);
298 if (bread
!= nameLength
)
300 HeapFree( GetProcessHeap(), 0, itemNameA
);
304 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, NULL
, 0 );
305 This
->itemName
=HeapReAlloc(GetProcessHeap(),0,This
->itemName
,lenW
*sizeof(WCHAR
));
308 HeapFree( GetProcessHeap(), 0, itemNameA
);
309 return E_OUTOFMEMORY
;
311 MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, This
->itemName
, lenW
);
312 HeapFree( GetProcessHeap(), 0, itemNameA
);
317 /******************************************************************************
319 ******************************************************************************/
320 HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
,
321 IStream
* pStm
,/* pointer to the stream where the object is to be saved */
322 BOOL fClearDirty
)/* Specifies whether to clear the dirty flag */
324 ICOM_THIS(ItemMonikerImpl
,iface
);
326 CHAR
*itemNameA
,*itemDelimiterA
;
328 /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
329 /* 2) String (type A): item delimiter string ('\0' included) */
330 /* 3) DWORD : size of item name string ('\0' included) */
331 /* 4) String (type A): item name string ('\0' included) */
333 DWORD nameLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, NULL
, 0, NULL
, NULL
);
334 DWORD delimiterLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, NULL
, 0, NULL
, NULL
);
335 itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
);
336 itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
);
337 WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, itemNameA
, nameLength
, NULL
, NULL
);
338 WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, itemDelimiterA
, delimiterLength
, NULL
, NULL
);
340 res
=IStream_Write(pStm
,&delimiterLength
,sizeof(DWORD
),NULL
);
341 res
=IStream_Write(pStm
,itemDelimiterA
,delimiterLength
* sizeof(CHAR
),NULL
);
342 res
=IStream_Write(pStm
,&nameLength
,sizeof(DWORD
),NULL
);
343 res
=IStream_Write(pStm
,itemNameA
,nameLength
* sizeof(CHAR
),NULL
);
348 /******************************************************************************
349 * ItemMoniker_GetSizeMax
350 ******************************************************************************/
351 HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
,
352 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
354 ICOM_THIS(ItemMonikerImpl
,iface
);
355 DWORD delimiterLength
=lstrlenW(This
->itemDelimiter
)+1;
356 DWORD nameLength
=lstrlenW(This
->itemName
)+1;
358 TRACE("(%p,%p)\n",iface
,pcbSize
);
363 /* for more details see ItemMonikerImpl_Save coments */
365 pcbSize
->s
.LowPart
= sizeof(DWORD
) + /* DWORD which contains delimiter length */
366 delimiterLength
+ /* item delimiter string */
367 sizeof(DWORD
) + /* DWORD which contains item name length */
368 nameLength
+ /* item name string */
369 34; /* this constant was added ! because when I tested this function it usually */
370 /* returns 34 bytes more than the number of bytes used by IMoniker::Save function */
371 pcbSize
->s
.HighPart
=0;
376 /******************************************************************************
377 * ItemMoniker_Construct (local function)
378 *******************************************************************************/
379 HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* This
, LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
)
382 int sizeStr1
=lstrlenW(lpszItem
), sizeStr2
;
383 static const OLECHAR emptystr
[1];
386 TRACE("(%p,%p)\n",This
,lpszItem
);
388 /* Initialize the virtual fgunction table. */
389 This
->lpvtbl1
= &VT_ItemMonikerImpl
;
390 This
->lpvtbl2
= &VT_ROTDataImpl
;
393 This
->itemName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr1
+1));
395 return E_OUTOFMEMORY
;
396 lstrcpyW(This
->itemName
,lpszItem
);
399 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
401 delim
= lpszDelim
? lpszDelim
: emptystr
;
403 sizeStr2
=lstrlenW(delim
);
404 This
->itemDelimiter
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr2
+1));
405 if (!This
->itemDelimiter
) {
406 HeapFree(GetProcessHeap(),0,This
->itemName
);
407 return E_OUTOFMEMORY
;
409 lstrcpyW(This
->itemDelimiter
,delim
);
413 /******************************************************************************
414 * ItemMoniker_Destroy (local function)
415 *******************************************************************************/
416 HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* This
)
418 TRACE("(%p)\n",This
);
421 HeapFree(GetProcessHeap(),0,This
->itemName
);
423 if (This
->itemDelimiter
)
424 HeapFree(GetProcessHeap(),0,This
->itemDelimiter
);
426 HeapFree(GetProcessHeap(),0,This
);
431 /******************************************************************************
432 * ItemMoniker_BindToObject
433 ******************************************************************************/
434 HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,
440 ICOM_THIS(ItemMonikerImpl
,iface
);
443 IID refid
=IID_IOleItemContainer
;
444 IOleItemContainer
*poic
=0;
446 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
456 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&refid
,(void**)&poic
);
460 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,riid
,ppvResult
);
462 IOleItemContainer_Release(poic
);
468 /******************************************************************************
469 * ItemMoniker_BindToStorage
470 ******************************************************************************/
471 HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,
477 ICOM_THIS(ItemMonikerImpl
,iface
);
480 IOleItemContainer
*poic
=0;
482 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
489 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
493 res
=IOleItemContainer_GetObjectStorage(poic
,This
->itemName
,pbc
,riid
,ppvResult
);
495 IOleItemContainer_Release(poic
);
501 /******************************************************************************
503 ******************************************************************************/
504 HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,
506 DWORD dwReduceHowFar
,
507 IMoniker
** ppmkToLeft
,
508 IMoniker
** ppmkReduced
)
510 TRACE("(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
512 if (ppmkReduced
==NULL
)
515 ItemMonikerImpl_AddRef(iface
);
519 return MK_S_REDUCED_TO_SELF
;
521 /******************************************************************************
522 * ItemMoniker_ComposeWith
523 ******************************************************************************/
524 HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,
526 BOOL fOnlyIfNotGeneric
,
527 IMoniker
** ppmkComposite
)
531 IEnumMoniker
* penumMk
=0;
532 IMoniker
*pmostLeftMk
=0;
533 IMoniker
* tempMkComposite
=0;
535 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
537 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
542 IMoniker_IsSystemMoniker(pmkRight
,&mkSys
);
544 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
545 if(mkSys
==MKSYS_ANTIMONIKER
)
549 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
550 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
552 if(mkSys
==MKSYS_GENERICCOMPOSITE
){
554 res
=IMoniker_Enum(pmkRight
,TRUE
,&penumMk
);
559 res
=IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
);
561 IMoniker_IsSystemMoniker(pmostLeftMk
,&mkSys2
);
563 if(mkSys2
==MKSYS_ANTIMONIKER
){
565 IMoniker_Release(pmostLeftMk
);
567 tempMkComposite
=iface
;
568 IMoniker_AddRef(iface
);
570 while(IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
)==S_OK
){
572 res
=CreateGenericComposite(tempMkComposite
,pmostLeftMk
,ppmkComposite
);
574 IMoniker_Release(tempMkComposite
);
575 IMoniker_Release(pmostLeftMk
);
577 tempMkComposite
=*ppmkComposite
;
578 IMoniker_AddRef(tempMkComposite
);
583 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
585 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
586 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
587 a NULL moniker and a return value of MK_E_NEEDGENERIC */
589 if (!fOnlyIfNotGeneric
)
590 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
593 return MK_E_NEEDGENERIC
;
596 /******************************************************************************
598 ******************************************************************************/
599 HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
601 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
603 if (ppenumMoniker
== NULL
)
606 *ppenumMoniker
= NULL
;
611 /******************************************************************************
612 * ItemMoniker_IsEqual
613 ******************************************************************************/
614 HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
618 LPOLESTR dispName1
,dispName2
;
620 HRESULT res
= S_FALSE
;
622 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
624 if (!pmkOtherMoniker
) return S_FALSE
;
627 /* check if both are ItemMoniker */
628 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker
,&clsid
))) return S_FALSE
;
629 if(!IsEqualCLSID(&clsid
,&CLSID_ItemMoniker
)) return S_FALSE
;
631 /* check if both displaynames are the same */
632 if(SUCCEEDED ((res
= CreateBindCtx(0,&bind
)))) {
633 if(SUCCEEDED (IMoniker_GetDisplayName(iface
,bind
,NULL
,&dispName1
))) {
634 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&dispName2
))) {
635 if(lstrcmpW(dispName1
,dispName2
)==0) res
= S_OK
;
636 CoTaskMemFree(dispName2
);
638 CoTaskMemFree(dispName1
);
644 /******************************************************************************
646 ******************************************************************************/
647 HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
649 ICOM_THIS(ItemMonikerImpl
,iface
);
651 int h
= 0,i
,skip
,len
;
658 val
= This
->itemName
;
662 for (i
= len
; i
> 0; i
--) {
663 h
= (h
* 37) + val
[off
++];
666 /* only sample some characters */
668 for (i
= len
; i
> 0; i
-= skip
, off
+= skip
) {
669 h
= (h
* 39) + val
[off
];
678 /******************************************************************************
679 * ItemMoniker_IsRunning
680 ******************************************************************************/
681 HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,
684 IMoniker
* pmkNewlyRunning
)
686 IRunningObjectTable
* rot
;
688 IOleItemContainer
*poic
=0;
689 ICOM_THIS(ItemMonikerImpl
,iface
);
691 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
693 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
694 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
696 if ((pmkNewlyRunning
!=NULL
)&&(IMoniker_IsEqual(pmkNewlyRunning
,iface
)==S_OK
))
702 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
707 res
= IRunningObjectTable_IsRunning(rot
,iface
);
709 IRunningObjectTable_Release(rot
);
713 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
714 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
715 /* passing the string contained within this moniker. */
717 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
721 res
=IOleItemContainer_IsRunning(poic
,This
->itemName
);
723 IOleItemContainer_Release(poic
);
730 /******************************************************************************
731 * ItemMoniker_GetTimeOfLastChange
732 ******************************************************************************/
733 HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
738 IRunningObjectTable
* rot
;
740 IMoniker
*compositeMk
;
742 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pItemTime
);
747 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
750 return MK_E_NOTBINDABLE
;
753 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
754 /* the time of last change. If the object is not in the ROT, the method calls */
755 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
757 res
=CreateGenericComposite(pmkToLeft
,iface
,&compositeMk
);
759 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
761 if (IRunningObjectTable_GetTimeOfLastChange(rot
,compositeMk
,pItemTime
)!=S_OK
)
763 res
=IMoniker_GetTimeOfLastChange(pmkToLeft
,pbc
,NULL
,pItemTime
);
765 IMoniker_Release(compositeMk
);
771 /******************************************************************************
772 * ItemMoniker_Inverse
773 ******************************************************************************/
774 HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
776 TRACE("(%p,%p)\n",iface
,ppmk
);
781 return CreateAntiMoniker(ppmk
);
784 /******************************************************************************
785 * ItemMoniker_CommonPrefixWith
786 ******************************************************************************/
787 HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
790 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
791 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
792 /* to this moniker and returns MK_S_US */
794 if((mkSys
==MKSYS_ITEMMONIKER
) && (IMoniker_IsEqual(iface
,pmkOther
)==S_OK
) ){
798 IMoniker_AddRef(iface
);
803 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
804 /* the case where the other moniker is a generic composite. */
805 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
808 /******************************************************************************
809 * ItemMoniker_RelativePathTo
810 ******************************************************************************/
811 HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
813 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
815 if (ppmkRelPath
==NULL
)
820 return MK_E_NOTBINDABLE
;
823 /******************************************************************************
824 * ItemMoniker_GetDisplayName
825 ******************************************************************************/
826 HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,
829 LPOLESTR
*ppszDisplayName
)
831 ICOM_THIS(ItemMonikerImpl
,iface
);
833 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
835 if (ppszDisplayName
==NULL
)
838 if (pmkToLeft
!=NULL
){
842 *ppszDisplayName
=CoTaskMemAlloc(sizeof(WCHAR
)*(lstrlenW(This
->itemDelimiter
)+lstrlenW(This
->itemName
)+1));
844 if (*ppszDisplayName
==NULL
)
845 return E_OUTOFMEMORY
;
847 lstrcpyW(*ppszDisplayName
,This
->itemDelimiter
);
848 lstrcatW(*ppszDisplayName
,This
->itemName
);
853 /******************************************************************************
854 * ItemMoniker_ParseDisplayName
855 ******************************************************************************/
856 HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,
859 LPOLESTR pszDisplayName
,
863 IOleItemContainer
* poic
=0;
864 IParseDisplayName
* ppdn
=0;
865 LPOLESTR displayName
;
867 ICOM_THIS(ItemMonikerImpl
,iface
);
869 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
875 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
876 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
877 /* name to IParseDisplayName::ParseDisplayName */
878 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
882 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,&IID_IParseDisplayName
,(void**)&ppdn
);
884 res
=IMoniker_GetDisplayName(iface
,pbc
,NULL
,&displayName
);
886 res
=IParseDisplayName_ParseDisplayName(ppdn
,pbc
,displayName
,pchEaten
,ppmkOut
);
888 IOleItemContainer_Release(poic
);
889 IParseDisplayName_Release(ppdn
);
895 /******************************************************************************
896 * ItemMoniker_IsSystemMoniker
897 ******************************************************************************/
898 HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
900 TRACE("(%p,%p)\n",iface
,pwdMksys
);
905 (*pwdMksys
)=MKSYS_ITEMMONIKER
;
910 /*******************************************************************************
911 * ItemMonikerIROTData_QueryInterface
912 *******************************************************************************/
913 HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
916 ICOM_THIS_From_IROTData(IMoniker
, iface
);
918 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
920 return ItemMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
923 /***********************************************************************
924 * ItemMonikerIROTData_AddRef
926 ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
*iface
)
928 ICOM_THIS_From_IROTData(IMoniker
, iface
);
930 TRACE("(%p)\n",iface
);
932 return ItemMonikerImpl_AddRef(This
);
935 /***********************************************************************
936 * ItemMonikerIROTData_Release
938 ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
)
940 ICOM_THIS_From_IROTData(IMoniker
, iface
);
942 TRACE("(%p)\n",iface
);
944 return ItemMonikerImpl_Release(This
);
947 /******************************************************************************
948 * ItemMonikerIROTData_GetComparaisonData
949 ******************************************************************************/
950 HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,
959 /******************************************************************************
960 * CreateItemMoniker16 [OLE2.28]
961 ******************************************************************************/
962 HRESULT WINAPI
CreateItemMoniker16(LPCOLESTR16 lpszDelim
,LPCOLESTR lpszItem
,LPMONIKER
* ppmk
)
965 FIXME("(%s,%p),stub!\n",lpszDelim
,ppmk
);
970 /******************************************************************************
971 * CreateItemMoniker [OLE32.58]
972 ******************************************************************************/
973 HRESULT WINAPI
CreateItemMoniker(LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
, LPMONIKER
* ppmk
)
975 ItemMonikerImpl
* newItemMoniker
= 0;
977 IID riid
=IID_IMoniker
;
979 TRACE("(%p,%p,%p)\n",lpszDelim
,lpszItem
,ppmk
);
981 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
983 if (newItemMoniker
== 0)
984 return STG_E_INSUFFICIENTMEMORY
;
986 hr
= ItemMonikerImpl_Construct(newItemMoniker
,lpszDelim
,lpszItem
);
990 HeapFree(GetProcessHeap(),0,newItemMoniker
);
994 return ItemMonikerImpl_QueryInterface((IMoniker
*)newItemMoniker
,&riid
,(void**)ppmk
);