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
32 #include "wine/debug.h"
34 #include "wine/unicode.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
39 const CLSID CLSID_ItemMoniker
= {
40 0x304, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
43 /* ItemMoniker data structure */
44 typedef struct ItemMonikerImpl
{
46 IMonikerVtbl
* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
48 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
49 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
51 IROTDataVtbl
* lpvtbl2
; /* VTable relative to the IROTData interface.*/
53 ULONG ref
; /* reference counter for this object */
55 LPOLESTR itemName
; /* item name identified by this ItemMoniker */
57 LPOLESTR itemDelimiter
; /* Delimiter string */
61 /********************************************************************************/
62 /* ItemMoniker prototype functions : */
64 /* IUnknown prototype functions */
65 static HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
);
66 static ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
);
67 static ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
);
69 /* IPersist prototype functions */
70 static HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
, CLSID
*pClassID
);
72 /* IPersistStream prototype functions */
73 static HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
);
74 static HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
, IStream
* pStm
);
75 static HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
);
76 static HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
);
78 /* IMoniker prototype functions */
79 static HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
80 static HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
81 static HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,IBindCtx
* pbc
, DWORD dwReduceHowFar
,IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
);
82 static HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,IMoniker
* pmkRight
,BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
);
83 static HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
);
84 static HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
);
85 static HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
);
86 static HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, IMoniker
* pmkNewlyRunning
);
87 static HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
, FILETIME
* pItemTime
);
88 static HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
);
89 static HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
, IMoniker
** ppmkPrefix
);
90 static HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
);
91 static HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
);
92 static HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
);
93 static HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
);
95 /* Local function used by ItemMoniker implementation */
96 HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* iface
, LPCOLESTR lpszDelim
,LPCOLESTR lpszPathName
);
97 HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* iface
);
99 /********************************************************************************/
100 /* IROTData prototype functions */
102 /* IUnknown prototype functions */
103 static HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
* iface
,REFIID riid
,VOID
** ppvObject
);
104 static ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
* iface
);
105 static ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
);
107 /* IROTData prototype function */
108 static HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,BYTE
* pbData
,ULONG cbMax
,ULONG
* pcbData
);
110 /********************************************************************************/
111 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
112 /* IPersistStream and IMoniker functions. */
113 static IMonikerVtbl VT_ItemMonikerImpl
=
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 IROTDataVtbl VT_ROTDataImpl
=
144 ItemMonikerROTDataImpl_QueryInterface
,
145 ItemMonikerROTDataImpl_AddRef
,
146 ItemMonikerROTDataImpl_Release
,
147 ItemMonikerROTDataImpl_GetComparaisonData
150 /*******************************************************************************
151 * ItemMoniker_QueryInterface
152 *******************************************************************************/
153 HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
155 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
157 TRACE("(%p,%p,%p)\n",This
,riid
,ppvObject
);
159 /* Perform a sanity check on the parameters.*/
160 if ( (This
==0) || (ppvObject
==0) )
163 /* Initialize the return parameter */
166 /* Compare the riid with the interface IDs implemented by this object.*/
167 if (IsEqualIID(&IID_IUnknown
, riid
) ||
168 IsEqualIID(&IID_IPersist
, riid
) ||
169 IsEqualIID(&IID_IPersistStream
, riid
) ||
170 IsEqualIID(&IID_IMoniker
, riid
)
174 else if (IsEqualIID(&IID_IROTData
, riid
))
175 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
177 /* Check that we obtained an interface.*/
179 return E_NOINTERFACE
;
181 /* Query Interface always increases the reference count by one when it is successful */
182 ItemMonikerImpl_AddRef(iface
);
187 /******************************************************************************
189 ******************************************************************************/
190 ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
)
192 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
194 TRACE("(%p)\n",This
);
196 return InterlockedIncrement(&This
->ref
);
199 /******************************************************************************
200 * ItemMoniker_Release
201 ******************************************************************************/
202 ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
)
204 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
207 TRACE("(%p)\n",This
);
209 ref
= InterlockedDecrement(&This
->ref
);
211 /* destroy the object if there's no more reference on it */
212 if (ref
== 0) ItemMonikerImpl_Destroy(This
);
217 /******************************************************************************
218 * ItemMoniker_GetClassID
219 ******************************************************************************/
220 HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
222 TRACE("(%p,%p),stub!\n",iface
,pClassID
);
227 *pClassID
= CLSID_ItemMoniker
;
232 /******************************************************************************
233 * ItemMoniker_IsDirty
234 ******************************************************************************/
235 HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
)
237 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
238 method in the OLE-provided moniker interfaces always return S_FALSE because
239 their internal state never changes. */
241 TRACE("(%p)\n",iface
);
246 /******************************************************************************
248 ******************************************************************************/
249 HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
252 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
254 DWORD delimiterLength
,nameLength
,lenW
;
255 CHAR
*itemNameA
,*itemDelimiterA
;
258 /* for more details about data read by this function see coments of ItemMonikerImpl_Save function */
260 /* read item delimiter string length + 1 */
261 res
=IStream_Read(pStm
,&delimiterLength
,sizeof(DWORD
),&bread
);
262 if (bread
!= sizeof(DWORD
))
265 /* read item delimiter string */
266 if (!(itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
)))
267 return E_OUTOFMEMORY
;
268 res
=IStream_Read(pStm
,itemDelimiterA
,delimiterLength
,&bread
);
269 if (bread
!= delimiterLength
)
271 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
275 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, NULL
, 0 );
276 This
->itemDelimiter
=HeapReAlloc(GetProcessHeap(),0,This
->itemDelimiter
,lenW
*sizeof(WCHAR
));
277 if (!This
->itemDelimiter
)
279 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
280 return E_OUTOFMEMORY
;
282 MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, This
->itemDelimiter
, lenW
);
283 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
285 /* read item name string length + 1*/
286 res
=IStream_Read(pStm
,&nameLength
,sizeof(DWORD
),&bread
);
287 if (bread
!= sizeof(DWORD
))
290 /* read item name string */
291 if (!(itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
)))
292 return E_OUTOFMEMORY
;
293 res
=IStream_Read(pStm
,itemNameA
,nameLength
,&bread
);
294 if (bread
!= nameLength
)
296 HeapFree( GetProcessHeap(), 0, itemNameA
);
300 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, NULL
, 0 );
301 This
->itemName
=HeapReAlloc(GetProcessHeap(),0,This
->itemName
,lenW
*sizeof(WCHAR
));
304 HeapFree( GetProcessHeap(), 0, itemNameA
);
305 return E_OUTOFMEMORY
;
307 MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, This
->itemName
, lenW
);
308 HeapFree( GetProcessHeap(), 0, itemNameA
);
313 /******************************************************************************
315 ******************************************************************************/
316 HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
,
317 IStream
* pStm
,/* pointer to the stream where the object is to be saved */
318 BOOL fClearDirty
)/* Specifies whether to clear the dirty flag */
320 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
322 CHAR
*itemNameA
,*itemDelimiterA
;
324 /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
325 /* 2) String (type A): item delimiter string ('\0' included) */
326 /* 3) DWORD : size of item name string ('\0' included) */
327 /* 4) String (type A): item name string ('\0' included) */
329 DWORD nameLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, NULL
, 0, NULL
, NULL
);
330 DWORD delimiterLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, NULL
, 0, NULL
, NULL
);
331 itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
);
332 itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
);
333 WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, itemNameA
, nameLength
, NULL
, NULL
);
334 WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, itemDelimiterA
, delimiterLength
, NULL
, NULL
);
336 res
=IStream_Write(pStm
,&delimiterLength
,sizeof(DWORD
),NULL
);
337 res
=IStream_Write(pStm
,itemDelimiterA
,delimiterLength
* sizeof(CHAR
),NULL
);
338 res
=IStream_Write(pStm
,&nameLength
,sizeof(DWORD
),NULL
);
339 res
=IStream_Write(pStm
,itemNameA
,nameLength
* sizeof(CHAR
),NULL
);
344 /******************************************************************************
345 * ItemMoniker_GetSizeMax
346 ******************************************************************************/
347 HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
,
348 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
350 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
351 DWORD delimiterLength
=lstrlenW(This
->itemDelimiter
)+1;
352 DWORD nameLength
=lstrlenW(This
->itemName
)+1;
354 TRACE("(%p,%p)\n",iface
,pcbSize
);
359 /* for more details see ItemMonikerImpl_Save coments */
361 pcbSize
->u
.LowPart
= sizeof(DWORD
) + /* DWORD which contains delimiter length */
362 delimiterLength
+ /* item delimiter string */
363 sizeof(DWORD
) + /* DWORD which contains item name length */
364 nameLength
+ /* item name string */
365 34; /* this constant was added ! because when I tested this function it usually */
366 /* returns 34 bytes more than the number of bytes used by IMoniker::Save function */
367 pcbSize
->u
.HighPart
=0;
372 /******************************************************************************
373 * ItemMoniker_Construct (local function)
374 *******************************************************************************/
375 HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* This
, LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
)
378 int sizeStr1
=lstrlenW(lpszItem
), sizeStr2
;
379 static const OLECHAR emptystr
[1];
382 TRACE("(%p,%p)\n",This
,lpszItem
);
384 /* Initialize the virtual fgunction table. */
385 This
->lpvtbl1
= &VT_ItemMonikerImpl
;
386 This
->lpvtbl2
= &VT_ROTDataImpl
;
389 This
->itemName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr1
+1));
391 return E_OUTOFMEMORY
;
392 lstrcpyW(This
->itemName
,lpszItem
);
395 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
397 delim
= lpszDelim
? lpszDelim
: emptystr
;
399 sizeStr2
=lstrlenW(delim
);
400 This
->itemDelimiter
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr2
+1));
401 if (!This
->itemDelimiter
) {
402 HeapFree(GetProcessHeap(),0,This
->itemName
);
403 return E_OUTOFMEMORY
;
405 lstrcpyW(This
->itemDelimiter
,delim
);
409 /******************************************************************************
410 * ItemMoniker_Destroy (local function)
411 *******************************************************************************/
412 HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* This
)
414 TRACE("(%p)\n",This
);
417 HeapFree(GetProcessHeap(),0,This
->itemName
);
419 if (This
->itemDelimiter
)
420 HeapFree(GetProcessHeap(),0,This
->itemDelimiter
);
422 HeapFree(GetProcessHeap(),0,This
);
427 /******************************************************************************
428 * ItemMoniker_BindToObject
429 ******************************************************************************/
430 HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,
436 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
439 IID refid
=IID_IOleItemContainer
;
440 IOleItemContainer
*poic
=0;
442 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
452 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&refid
,(void**)&poic
);
456 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,riid
,ppvResult
);
458 IOleItemContainer_Release(poic
);
464 /******************************************************************************
465 * ItemMoniker_BindToStorage
466 ******************************************************************************/
467 HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,
473 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
476 IOleItemContainer
*poic
=0;
478 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
485 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
489 res
=IOleItemContainer_GetObjectStorage(poic
,This
->itemName
,pbc
,riid
,ppvResult
);
491 IOleItemContainer_Release(poic
);
497 /******************************************************************************
499 ******************************************************************************/
500 HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,
502 DWORD dwReduceHowFar
,
503 IMoniker
** ppmkToLeft
,
504 IMoniker
** ppmkReduced
)
506 TRACE("(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
508 if (ppmkReduced
==NULL
)
511 ItemMonikerImpl_AddRef(iface
);
515 return MK_S_REDUCED_TO_SELF
;
517 /******************************************************************************
518 * ItemMoniker_ComposeWith
519 ******************************************************************************/
520 HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,
522 BOOL fOnlyIfNotGeneric
,
523 IMoniker
** ppmkComposite
)
527 IEnumMoniker
* penumMk
=0;
528 IMoniker
*pmostLeftMk
=0;
529 IMoniker
* tempMkComposite
=0;
531 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
533 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
538 IMoniker_IsSystemMoniker(pmkRight
,&mkSys
);
540 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
541 if(mkSys
==MKSYS_ANTIMONIKER
)
545 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
546 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
548 if(mkSys
==MKSYS_GENERICCOMPOSITE
){
550 res
=IMoniker_Enum(pmkRight
,TRUE
,&penumMk
);
555 res
=IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
);
557 IMoniker_IsSystemMoniker(pmostLeftMk
,&mkSys2
);
559 if(mkSys2
==MKSYS_ANTIMONIKER
){
561 IMoniker_Release(pmostLeftMk
);
563 tempMkComposite
=iface
;
564 IMoniker_AddRef(iface
);
566 while(IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
)==S_OK
){
568 res
=CreateGenericComposite(tempMkComposite
,pmostLeftMk
,ppmkComposite
);
570 IMoniker_Release(tempMkComposite
);
571 IMoniker_Release(pmostLeftMk
);
573 tempMkComposite
=*ppmkComposite
;
574 IMoniker_AddRef(tempMkComposite
);
579 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
581 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
582 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
583 a NULL moniker and a return value of MK_E_NEEDGENERIC */
585 if (!fOnlyIfNotGeneric
)
586 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
589 return MK_E_NEEDGENERIC
;
592 /******************************************************************************
594 ******************************************************************************/
595 HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
597 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
599 if (ppenumMoniker
== NULL
)
602 *ppenumMoniker
= NULL
;
607 /******************************************************************************
608 * ItemMoniker_IsEqual
609 ******************************************************************************/
610 HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
614 LPOLESTR dispName1
,dispName2
;
616 HRESULT res
= S_FALSE
;
618 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
620 if (!pmkOtherMoniker
) return S_FALSE
;
623 /* check if both are ItemMoniker */
624 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker
,&clsid
))) return S_FALSE
;
625 if(!IsEqualCLSID(&clsid
,&CLSID_ItemMoniker
)) return S_FALSE
;
627 /* check if both displaynames are the same */
628 if(SUCCEEDED ((res
= CreateBindCtx(0,&bind
)))) {
629 if(SUCCEEDED (IMoniker_GetDisplayName(iface
,bind
,NULL
,&dispName1
))) {
630 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&dispName2
))) {
631 if(lstrcmpW(dispName1
,dispName2
)==0) res
= S_OK
;
632 CoTaskMemFree(dispName2
);
634 CoTaskMemFree(dispName1
);
640 /******************************************************************************
642 ******************************************************************************/
643 HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
645 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
647 int h
= 0,i
,skip
,len
;
654 val
= This
->itemName
;
658 for (i
= len
; i
> 0; i
--) {
659 h
= (h
* 37) + val
[off
++];
662 /* only sample some characters */
664 for (i
= len
; i
> 0; i
-= skip
, off
+= skip
) {
665 h
= (h
* 39) + val
[off
];
674 /******************************************************************************
675 * ItemMoniker_IsRunning
676 ******************************************************************************/
677 HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,
680 IMoniker
* pmkNewlyRunning
)
682 IRunningObjectTable
* rot
;
684 IOleItemContainer
*poic
=0;
685 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
687 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
689 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
690 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
692 if ((pmkNewlyRunning
!=NULL
)&&(IMoniker_IsEqual(pmkNewlyRunning
,iface
)==S_OK
))
698 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
703 res
= IRunningObjectTable_IsRunning(rot
,iface
);
705 IRunningObjectTable_Release(rot
);
709 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
710 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
711 /* passing the string contained within this moniker. */
713 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
717 res
=IOleItemContainer_IsRunning(poic
,This
->itemName
);
719 IOleItemContainer_Release(poic
);
726 /******************************************************************************
727 * ItemMoniker_GetTimeOfLastChange
728 ******************************************************************************/
729 HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
734 IRunningObjectTable
* rot
;
736 IMoniker
*compositeMk
;
738 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pItemTime
);
743 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
746 return MK_E_NOTBINDABLE
;
749 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
750 /* the time of last change. If the object is not in the ROT, the method calls */
751 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
753 res
=CreateGenericComposite(pmkToLeft
,iface
,&compositeMk
);
755 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
757 if (IRunningObjectTable_GetTimeOfLastChange(rot
,compositeMk
,pItemTime
)!=S_OK
)
759 res
=IMoniker_GetTimeOfLastChange(pmkToLeft
,pbc
,NULL
,pItemTime
);
761 IMoniker_Release(compositeMk
);
767 /******************************************************************************
768 * ItemMoniker_Inverse
769 ******************************************************************************/
770 HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
772 TRACE("(%p,%p)\n",iface
,ppmk
);
777 return CreateAntiMoniker(ppmk
);
780 /******************************************************************************
781 * ItemMoniker_CommonPrefixWith
782 ******************************************************************************/
783 HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
786 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
787 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
788 /* to this moniker and returns MK_S_US */
790 if((mkSys
==MKSYS_ITEMMONIKER
) && (IMoniker_IsEqual(iface
,pmkOther
)==S_OK
) ){
794 IMoniker_AddRef(iface
);
799 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
800 /* the case where the other moniker is a generic composite. */
801 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
804 /******************************************************************************
805 * ItemMoniker_RelativePathTo
806 ******************************************************************************/
807 HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
809 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
811 if (ppmkRelPath
==NULL
)
816 return MK_E_NOTBINDABLE
;
819 /******************************************************************************
820 * ItemMoniker_GetDisplayName
821 ******************************************************************************/
822 HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,
825 LPOLESTR
*ppszDisplayName
)
827 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
829 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
831 if (ppszDisplayName
==NULL
)
834 if (pmkToLeft
!=NULL
){
838 *ppszDisplayName
=CoTaskMemAlloc(sizeof(WCHAR
)*(lstrlenW(This
->itemDelimiter
)+lstrlenW(This
->itemName
)+1));
840 if (*ppszDisplayName
==NULL
)
841 return E_OUTOFMEMORY
;
843 lstrcpyW(*ppszDisplayName
,This
->itemDelimiter
);
844 lstrcatW(*ppszDisplayName
,This
->itemName
);
849 /******************************************************************************
850 * ItemMoniker_ParseDisplayName
851 ******************************************************************************/
852 HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,
855 LPOLESTR pszDisplayName
,
859 IOleItemContainer
* poic
=0;
860 IParseDisplayName
* ppdn
=0;
861 LPOLESTR displayName
;
863 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
865 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
871 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
872 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
873 /* name to IParseDisplayName::ParseDisplayName */
874 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
878 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,&IID_IParseDisplayName
,(void**)&ppdn
);
880 res
=IMoniker_GetDisplayName(iface
,pbc
,NULL
,&displayName
);
882 res
=IParseDisplayName_ParseDisplayName(ppdn
,pbc
,displayName
,pchEaten
,ppmkOut
);
884 IOleItemContainer_Release(poic
);
885 IParseDisplayName_Release(ppdn
);
891 /******************************************************************************
892 * ItemMoniker_IsSystemMoniker
893 ******************************************************************************/
894 HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
896 TRACE("(%p,%p)\n",iface
,pwdMksys
);
901 (*pwdMksys
)=MKSYS_ITEMMONIKER
;
906 /*******************************************************************************
907 * ItemMonikerIROTData_QueryInterface
908 *******************************************************************************/
909 HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
912 ICOM_THIS_From_IROTData(IMoniker
, iface
);
914 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
916 return ItemMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
919 /***********************************************************************
920 * ItemMonikerIROTData_AddRef
922 ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
*iface
)
924 ICOM_THIS_From_IROTData(IMoniker
, iface
);
926 TRACE("(%p)\n",iface
);
928 return ItemMonikerImpl_AddRef(This
);
931 /***********************************************************************
932 * ItemMonikerIROTData_Release
934 ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
)
936 ICOM_THIS_From_IROTData(IMoniker
, iface
);
938 TRACE("(%p)\n",iface
);
940 return ItemMonikerImpl_Release(This
);
943 /******************************************************************************
944 * ItemMonikerIROTData_GetComparaisonData
945 ******************************************************************************/
946 HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,
955 /******************************************************************************
956 * CreateItemMoniker [OLE32.@]
957 ******************************************************************************/
958 HRESULT WINAPI
CreateItemMoniker(LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
, LPMONIKER
* ppmk
)
960 ItemMonikerImpl
* newItemMoniker
= 0;
962 IID riid
=IID_IMoniker
;
964 TRACE("(%p,%p,%p)\n",lpszDelim
,lpszItem
,ppmk
);
966 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
968 if (newItemMoniker
== 0)
969 return STG_E_INSUFFICIENTMEMORY
;
971 hr
= ItemMonikerImpl_Construct(newItemMoniker
,lpszDelim
,lpszItem
);
975 HeapFree(GetProcessHeap(),0,newItemMoniker
);
979 return ItemMonikerImpl_QueryInterface((IMoniker
*)newItemMoniker
,&riid
,(void**)ppmk
);