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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
36 #include "wine/unicode.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
41 /* ItemMoniker data structure */
42 typedef struct ItemMonikerImpl
{
44 const IMonikerVtbl
* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
46 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
47 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
49 const IROTDataVtbl
* lpvtbl2
; /* VTable relative to the IROTData interface.*/
51 LONG ref
; /* reference counter for this object */
53 LPOLESTR itemName
; /* item name identified by this ItemMoniker */
55 LPOLESTR itemDelimiter
; /* Delimiter string */
57 IUnknown
*pMarshal
; /* custom marshaler */
60 static inline IMoniker
*impl_from_IROTData( IROTData
*iface
)
62 return (IMoniker
*)((char*)iface
- FIELD_OFFSET(ItemMonikerImpl
, lpvtbl2
));
65 /********************************************************************************/
66 /* ItemMoniker prototype functions : */
68 /* IUnknown prototype functions */
69 static HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
);
70 static ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
);
71 static ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
);
73 /* IPersist prototype functions */
74 static HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
, CLSID
*pClassID
);
76 /* IPersistStream prototype functions */
77 static HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
);
78 static HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
, IStream
* pStm
);
79 static HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
);
80 static HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
);
82 /* IMoniker prototype functions */
83 static HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
84 static HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
85 static HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,IBindCtx
* pbc
, DWORD dwReduceHowFar
,IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
);
86 static HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,IMoniker
* pmkRight
,BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
);
87 static HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
);
88 static HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
);
89 static HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
);
90 static HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, IMoniker
* pmkNewlyRunning
);
91 static HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
, FILETIME
* pItemTime
);
92 static HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
);
93 static HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
, IMoniker
** ppmkPrefix
);
94 static HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
);
95 static HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
);
96 static HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
);
97 static HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
);
99 /* Local function used by ItemMoniker implementation */
100 static HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* iface
, LPCOLESTR lpszDelim
,LPCOLESTR lpszPathName
);
101 static HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* iface
);
103 /********************************************************************************/
104 /* IROTData prototype functions */
106 /* IUnknown prototype functions */
107 static HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
* iface
,REFIID riid
,VOID
** ppvObject
);
108 static ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
* iface
);
109 static ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
);
111 /* IROTData prototype function */
112 static HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparisonData(IROTData
* iface
,BYTE
* pbData
,ULONG cbMax
,ULONG
* pcbData
);
114 /********************************************************************************/
115 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
116 /* IPersistStream and IMoniker functions. */
117 static const IMonikerVtbl VT_ItemMonikerImpl
=
119 ItemMonikerImpl_QueryInterface
,
120 ItemMonikerImpl_AddRef
,
121 ItemMonikerImpl_Release
,
122 ItemMonikerImpl_GetClassID
,
123 ItemMonikerImpl_IsDirty
,
124 ItemMonikerImpl_Load
,
125 ItemMonikerImpl_Save
,
126 ItemMonikerImpl_GetSizeMax
,
127 ItemMonikerImpl_BindToObject
,
128 ItemMonikerImpl_BindToStorage
,
129 ItemMonikerImpl_Reduce
,
130 ItemMonikerImpl_ComposeWith
,
131 ItemMonikerImpl_Enum
,
132 ItemMonikerImpl_IsEqual
,
133 ItemMonikerImpl_Hash
,
134 ItemMonikerImpl_IsRunning
,
135 ItemMonikerImpl_GetTimeOfLastChange
,
136 ItemMonikerImpl_Inverse
,
137 ItemMonikerImpl_CommonPrefixWith
,
138 ItemMonikerImpl_RelativePathTo
,
139 ItemMonikerImpl_GetDisplayName
,
140 ItemMonikerImpl_ParseDisplayName
,
141 ItemMonikerImpl_IsSystemMoniker
144 /********************************************************************************/
145 /* Virtual function table for the IROTData class. */
146 static const IROTDataVtbl VT_ROTDataImpl
=
148 ItemMonikerROTDataImpl_QueryInterface
,
149 ItemMonikerROTDataImpl_AddRef
,
150 ItemMonikerROTDataImpl_Release
,
151 ItemMonikerROTDataImpl_GetComparisonData
154 /*******************************************************************************
155 * ItemMoniker_QueryInterface
156 *******************************************************************************/
157 HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
159 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
161 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppvObject
);
163 /* Perform a sanity check on the parameters.*/
164 if ( (This
==0) || (ppvObject
==0) )
167 /* Initialize the return parameter */
170 /* Compare the riid with the interface IDs implemented by this object.*/
171 if (IsEqualIID(&IID_IUnknown
, riid
) ||
172 IsEqualIID(&IID_IPersist
, riid
) ||
173 IsEqualIID(&IID_IPersistStream
, riid
) ||
174 IsEqualIID(&IID_IMoniker
, riid
)
178 else if (IsEqualIID(&IID_IROTData
, riid
))
179 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
180 else if (IsEqualIID(&IID_IMarshal
, riid
))
184 hr
= MonikerMarshal_Create(iface
, &This
->pMarshal
);
187 return IUnknown_QueryInterface(This
->pMarshal
, riid
, ppvObject
);
190 /* Check that we obtained an interface.*/
192 return E_NOINTERFACE
;
194 /* Query Interface always increases the reference count by one when it is successful */
195 ItemMonikerImpl_AddRef(iface
);
200 /******************************************************************************
202 ******************************************************************************/
203 ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
)
205 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
207 TRACE("(%p)\n",This
);
209 return InterlockedIncrement(&This
->ref
);
212 /******************************************************************************
213 * ItemMoniker_Release
214 ******************************************************************************/
215 ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
)
217 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
220 TRACE("(%p)\n",This
);
222 ref
= InterlockedDecrement(&This
->ref
);
224 /* destroy the object if there's no more reference on it */
225 if (ref
== 0) ItemMonikerImpl_Destroy(This
);
230 /******************************************************************************
231 * ItemMoniker_GetClassID
232 ******************************************************************************/
233 HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
235 TRACE("(%p,%p)\n",iface
,pClassID
);
240 *pClassID
= CLSID_ItemMoniker
;
245 /******************************************************************************
246 * ItemMoniker_IsDirty
247 ******************************************************************************/
248 HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
)
250 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
251 method in the OLE-provided moniker interfaces always return S_FALSE because
252 their internal state never changes. */
254 TRACE("(%p)\n",iface
);
259 /******************************************************************************
261 ******************************************************************************/
262 HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
265 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
267 DWORD delimiterLength
,nameLength
,lenW
;
268 CHAR
*itemNameA
,*itemDelimiterA
;
273 /* for more details about data read by this function see comments of ItemMonikerImpl_Save function */
275 /* read item delimiter string length + 1 */
276 res
=IStream_Read(pStm
,&delimiterLength
,sizeof(DWORD
),&bread
);
277 if (bread
!= sizeof(DWORD
))
280 /* read item delimiter string */
281 if (!(itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
)))
282 return E_OUTOFMEMORY
;
283 res
=IStream_Read(pStm
,itemDelimiterA
,delimiterLength
,&bread
);
284 if (bread
!= delimiterLength
)
286 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
290 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, NULL
, 0 );
291 This
->itemDelimiter
=HeapReAlloc(GetProcessHeap(),0,This
->itemDelimiter
,lenW
*sizeof(WCHAR
));
292 if (!This
->itemDelimiter
)
294 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
295 return E_OUTOFMEMORY
;
297 MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, This
->itemDelimiter
, lenW
);
298 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
300 /* read item name string length + 1*/
301 res
=IStream_Read(pStm
,&nameLength
,sizeof(DWORD
),&bread
);
302 if (bread
!= sizeof(DWORD
))
305 /* read item name string */
306 if (!(itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
)))
307 return E_OUTOFMEMORY
;
308 res
=IStream_Read(pStm
,itemNameA
,nameLength
,&bread
);
309 if (bread
!= nameLength
)
311 HeapFree( GetProcessHeap(), 0, itemNameA
);
315 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, NULL
, 0 );
316 This
->itemName
=HeapReAlloc(GetProcessHeap(),0,This
->itemName
,lenW
*sizeof(WCHAR
));
319 HeapFree( GetProcessHeap(), 0, itemNameA
);
320 return E_OUTOFMEMORY
;
322 MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, This
->itemName
, lenW
);
323 HeapFree( GetProcessHeap(), 0, itemNameA
);
328 /******************************************************************************
330 ******************************************************************************/
331 HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
,
332 IStream
* pStm
,/* pointer to the stream where the object is to be saved */
333 BOOL fClearDirty
)/* Specifies whether to clear the dirty flag */
335 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
337 CHAR
*itemNameA
,*itemDelimiterA
;
339 /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
340 /* 2) String (type A): item delimiter string ('\0' included) */
341 /* 3) DWORD : size of item name string ('\0' included) */
342 /* 4) String (type A): item name string ('\0' included) */
344 DWORD nameLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, NULL
, 0, NULL
, NULL
);
345 DWORD delimiterLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, NULL
, 0, NULL
, NULL
);
346 itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
);
347 itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
);
348 WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, itemNameA
, nameLength
, NULL
, NULL
);
349 WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, itemDelimiterA
, delimiterLength
, NULL
, NULL
);
351 TRACE("%p, %s\n", pStm
, fClearDirty
? "TRUE" : "FALSE");
353 res
=IStream_Write(pStm
,&delimiterLength
,sizeof(DWORD
),NULL
);
354 res
=IStream_Write(pStm
,itemDelimiterA
,delimiterLength
* sizeof(CHAR
),NULL
);
355 res
=IStream_Write(pStm
,&nameLength
,sizeof(DWORD
),NULL
);
356 res
=IStream_Write(pStm
,itemNameA
,nameLength
* sizeof(CHAR
),NULL
);
358 HeapFree(GetProcessHeap(), 0, itemNameA
);
359 HeapFree(GetProcessHeap(), 0, itemDelimiterA
);
364 /******************************************************************************
365 * ItemMoniker_GetSizeMax
366 ******************************************************************************/
367 HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
,
368 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
370 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
371 DWORD delimiterLength
=lstrlenW(This
->itemDelimiter
)+1;
372 DWORD nameLength
=lstrlenW(This
->itemName
)+1;
374 TRACE("(%p,%p)\n",iface
,pcbSize
);
379 /* for more details see ItemMonikerImpl_Save comments */
381 pcbSize
->u
.LowPart
= sizeof(DWORD
) + /* DWORD which contains delimiter length */
382 delimiterLength
*4 + /* item delimiter string */
383 sizeof(DWORD
) + /* DWORD which contains item name length */
384 nameLength
*4 + /* item name string */
385 18; /* strange, but true */
386 pcbSize
->u
.HighPart
=0;
391 /******************************************************************************
392 * ItemMoniker_Construct (local function)
393 *******************************************************************************/
394 static HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* This
, LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
)
397 int sizeStr1
=lstrlenW(lpszItem
), sizeStr2
;
398 static const OLECHAR emptystr
[1];
401 TRACE("(%p,%s,%s)\n",This
,debugstr_w(lpszDelim
),debugstr_w(lpszItem
));
403 /* Initialize the virtual function table. */
404 This
->lpvtbl1
= &VT_ItemMonikerImpl
;
405 This
->lpvtbl2
= &VT_ROTDataImpl
;
407 This
->pMarshal
= NULL
;
409 This
->itemName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr1
+1));
411 return E_OUTOFMEMORY
;
412 lstrcpyW(This
->itemName
,lpszItem
);
415 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
417 delim
= lpszDelim
? lpszDelim
: emptystr
;
419 sizeStr2
=lstrlenW(delim
);
420 This
->itemDelimiter
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr2
+1));
421 if (!This
->itemDelimiter
) {
422 HeapFree(GetProcessHeap(),0,This
->itemName
);
423 return E_OUTOFMEMORY
;
425 lstrcpyW(This
->itemDelimiter
,delim
);
429 /******************************************************************************
430 * ItemMoniker_Destroy (local function)
431 *******************************************************************************/
432 static HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* This
)
434 TRACE("(%p)\n",This
);
436 if (This
->pMarshal
) IUnknown_Release(This
->pMarshal
);
437 HeapFree(GetProcessHeap(),0,This
->itemName
);
438 HeapFree(GetProcessHeap(),0,This
->itemDelimiter
);
439 HeapFree(GetProcessHeap(),0,This
);
444 /******************************************************************************
445 * ItemMoniker_BindToObject
446 ******************************************************************************/
447 HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,
453 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
456 IID refid
=IID_IOleItemContainer
;
457 IOleItemContainer
*poic
=0;
459 TRACE("(%p,%p,%p,%s,%p)\n",iface
,pbc
,pmkToLeft
,debugstr_guid(riid
),ppvResult
);
469 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&refid
,(void**)&poic
);
473 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,riid
,ppvResult
);
475 IOleItemContainer_Release(poic
);
481 /******************************************************************************
482 * ItemMoniker_BindToStorage
483 ******************************************************************************/
484 HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,
490 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
493 IOleItemContainer
*poic
=0;
495 TRACE("(%p,%p,%p,%s,%p)\n",iface
,pbc
,pmkToLeft
,debugstr_guid(riid
),ppvResult
);
502 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
506 res
=IOleItemContainer_GetObjectStorage(poic
,This
->itemName
,pbc
,riid
,ppvResult
);
508 IOleItemContainer_Release(poic
);
514 /******************************************************************************
516 ******************************************************************************/
517 HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,
519 DWORD dwReduceHowFar
,
520 IMoniker
** ppmkToLeft
,
521 IMoniker
** ppmkReduced
)
523 TRACE("(%p,%p,%d,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
525 if (ppmkReduced
==NULL
)
528 ItemMonikerImpl_AddRef(iface
);
532 return MK_S_REDUCED_TO_SELF
;
534 /******************************************************************************
535 * ItemMoniker_ComposeWith
536 ******************************************************************************/
537 HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,
539 BOOL fOnlyIfNotGeneric
,
540 IMoniker
** ppmkComposite
)
544 IEnumMoniker
* penumMk
=0;
545 IMoniker
*pmostLeftMk
=0;
546 IMoniker
* tempMkComposite
=0;
548 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
550 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
555 IMoniker_IsSystemMoniker(pmkRight
,&mkSys
);
557 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
558 if(mkSys
==MKSYS_ANTIMONIKER
)
562 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
563 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
565 if(mkSys
==MKSYS_GENERICCOMPOSITE
){
567 res
=IMoniker_Enum(pmkRight
,TRUE
,&penumMk
);
572 res
=IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
);
574 IMoniker_IsSystemMoniker(pmostLeftMk
,&mkSys2
);
576 if(mkSys2
==MKSYS_ANTIMONIKER
){
578 IMoniker_Release(pmostLeftMk
);
580 tempMkComposite
=iface
;
581 IMoniker_AddRef(iface
);
583 while(IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
)==S_OK
){
585 res
=CreateGenericComposite(tempMkComposite
,pmostLeftMk
,ppmkComposite
);
587 IMoniker_Release(tempMkComposite
);
588 IMoniker_Release(pmostLeftMk
);
590 tempMkComposite
=*ppmkComposite
;
591 IMoniker_AddRef(tempMkComposite
);
596 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
598 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
599 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
600 a NULL moniker and a return value of MK_E_NEEDGENERIC */
602 if (!fOnlyIfNotGeneric
)
603 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
606 return MK_E_NEEDGENERIC
;
609 /******************************************************************************
611 ******************************************************************************/
612 HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
614 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
616 if (ppenumMoniker
== NULL
)
619 *ppenumMoniker
= NULL
;
624 /******************************************************************************
625 * ItemMoniker_IsEqual
626 ******************************************************************************/
627 HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
631 LPOLESTR dispName1
,dispName2
;
633 HRESULT res
= S_FALSE
;
635 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
637 if (!pmkOtherMoniker
) return S_FALSE
;
640 /* check if both are ItemMoniker */
641 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker
,&clsid
))) return S_FALSE
;
642 if(!IsEqualCLSID(&clsid
,&CLSID_ItemMoniker
)) return S_FALSE
;
644 /* check if both displaynames are the same */
645 if(SUCCEEDED ((res
= CreateBindCtx(0,&bind
)))) {
646 if(SUCCEEDED (IMoniker_GetDisplayName(iface
,bind
,NULL
,&dispName1
))) {
647 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&dispName2
))) {
648 if(lstrcmpW(dispName1
,dispName2
)==0) res
= S_OK
;
649 CoTaskMemFree(dispName2
);
651 CoTaskMemFree(dispName1
);
657 /******************************************************************************
659 ******************************************************************************/
660 HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
662 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
671 val
= This
->itemName
;
674 for (i
= len
; i
> 0; i
--)
675 h
= (h
* 3) ^ toupperW(val
[off
++]);
682 /******************************************************************************
683 * ItemMoniker_IsRunning
684 ******************************************************************************/
685 HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,
688 IMoniker
* pmkNewlyRunning
)
690 IRunningObjectTable
* rot
;
692 IOleItemContainer
*poic
=0;
693 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
695 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
697 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
698 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
700 if ((pmkNewlyRunning
!=NULL
)&&(IMoniker_IsEqual(pmkNewlyRunning
,iface
)==S_OK
))
706 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
711 res
= IRunningObjectTable_IsRunning(rot
,iface
);
713 IRunningObjectTable_Release(rot
);
717 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
718 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
719 /* passing the string contained within this moniker. */
721 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
725 res
=IOleItemContainer_IsRunning(poic
,This
->itemName
);
727 IOleItemContainer_Release(poic
);
734 /******************************************************************************
735 * ItemMoniker_GetTimeOfLastChange
736 ******************************************************************************/
737 HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
742 IRunningObjectTable
* rot
;
744 IMoniker
*compositeMk
;
746 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pItemTime
);
751 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
754 return MK_E_NOTBINDABLE
;
757 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
758 /* the time of last change. If the object is not in the ROT, the method calls */
759 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
761 res
=CreateGenericComposite(pmkToLeft
,iface
,&compositeMk
);
763 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
765 if (IRunningObjectTable_GetTimeOfLastChange(rot
,compositeMk
,pItemTime
)!=S_OK
)
767 res
=IMoniker_GetTimeOfLastChange(pmkToLeft
,pbc
,NULL
,pItemTime
);
769 IMoniker_Release(compositeMk
);
775 /******************************************************************************
776 * ItemMoniker_Inverse
777 ******************************************************************************/
778 HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
780 TRACE("(%p,%p)\n",iface
,ppmk
);
785 return CreateAntiMoniker(ppmk
);
788 /******************************************************************************
789 * ItemMoniker_CommonPrefixWith
790 ******************************************************************************/
791 HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
795 TRACE("(%p,%p)\n", pmkOther
, ppmkPrefix
);
797 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
798 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
799 /* to this moniker and returns MK_S_US */
801 if((mkSys
==MKSYS_ITEMMONIKER
) && (IMoniker_IsEqual(iface
,pmkOther
)==S_OK
) ){
805 IMoniker_AddRef(iface
);
810 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
811 /* the case where the other moniker is a generic composite. */
812 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
815 /******************************************************************************
816 * ItemMoniker_RelativePathTo
817 ******************************************************************************/
818 HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
820 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
822 if (ppmkRelPath
==NULL
)
827 return MK_E_NOTBINDABLE
;
830 /******************************************************************************
831 * ItemMoniker_GetDisplayName
832 ******************************************************************************/
833 HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,
836 LPOLESTR
*ppszDisplayName
)
838 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
840 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
842 if (ppszDisplayName
==NULL
)
845 if (pmkToLeft
!=NULL
){
849 *ppszDisplayName
=CoTaskMemAlloc(sizeof(WCHAR
)*(lstrlenW(This
->itemDelimiter
)+lstrlenW(This
->itemName
)+1));
851 if (*ppszDisplayName
==NULL
)
852 return E_OUTOFMEMORY
;
854 lstrcpyW(*ppszDisplayName
,This
->itemDelimiter
);
855 lstrcatW(*ppszDisplayName
,This
->itemName
);
857 TRACE("-- %s\n", debugstr_w(*ppszDisplayName
));
862 /******************************************************************************
863 * ItemMoniker_ParseDisplayName
864 ******************************************************************************/
865 HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,
868 LPOLESTR pszDisplayName
,
872 IOleItemContainer
* poic
=0;
873 IParseDisplayName
* ppdn
=0;
874 LPOLESTR displayName
;
876 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
878 TRACE("%s\n", debugstr_w(pszDisplayName
));
880 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
886 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
887 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
888 /* name to IParseDisplayName::ParseDisplayName */
889 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
893 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,&IID_IParseDisplayName
,(void**)&ppdn
);
895 res
=IMoniker_GetDisplayName(iface
,pbc
,NULL
,&displayName
);
897 res
=IParseDisplayName_ParseDisplayName(ppdn
,pbc
,displayName
,pchEaten
,ppmkOut
);
899 IOleItemContainer_Release(poic
);
900 IParseDisplayName_Release(ppdn
);
906 /******************************************************************************
907 * ItemMoniker_IsSystemMoniker
908 ******************************************************************************/
909 HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
911 TRACE("(%p,%p)\n",iface
,pwdMksys
);
916 (*pwdMksys
)=MKSYS_ITEMMONIKER
;
921 /*******************************************************************************
922 * ItemMonikerIROTData_QueryInterface
923 *******************************************************************************/
924 HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
927 IMoniker
*This
= impl_from_IROTData(iface
);
929 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
931 return ItemMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
934 /***********************************************************************
935 * ItemMonikerIROTData_AddRef
937 ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
*iface
)
939 IMoniker
*This
= impl_from_IROTData(iface
);
941 TRACE("(%p)\n",iface
);
943 return ItemMonikerImpl_AddRef(This
);
946 /***********************************************************************
947 * ItemMonikerIROTData_Release
949 ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
)
951 IMoniker
*This
= impl_from_IROTData(iface
);
953 TRACE("(%p)\n",iface
);
955 return ItemMonikerImpl_Release(This
);
958 /******************************************************************************
959 * ItemMonikerIROTData_GetComparisonData
960 ******************************************************************************/
961 HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparisonData(IROTData
* iface
,
966 IMoniker
*This
= impl_from_IROTData(iface
);
967 ItemMonikerImpl
*This1
= (ItemMonikerImpl
*)This
;
968 int len
= (strlenW(This1
->itemName
)+1);
971 LPWSTR pszItemDelimiter
;
973 TRACE("(%p, %u, %p)\n", pbData
, cbMax
, pcbData
);
975 *pcbData
= sizeof(CLSID
) + sizeof(WCHAR
) + len
* sizeof(WCHAR
);
976 if (cbMax
< *pcbData
)
977 return E_OUTOFMEMORY
;
980 memcpy(pbData
, &CLSID_ItemMoniker
, sizeof(CLSID
));
981 /* write delimiter */
982 pszItemDelimiter
= (LPWSTR
)(pbData
+sizeof(CLSID
));
983 *pszItemDelimiter
= *This1
->itemDelimiter
;
985 pszItemName
= pszItemDelimiter
+ 1;
986 for (i
= 0; i
< len
; i
++)
987 pszItemName
[i
] = toupperW(This1
->itemName
[i
]);
992 /******************************************************************************
993 * CreateItemMoniker [OLE32.@]
994 ******************************************************************************/
995 HRESULT WINAPI
CreateItemMoniker(LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
, LPMONIKER
* ppmk
)
997 ItemMonikerImpl
* newItemMoniker
;
1000 TRACE("(%s,%s,%p)\n",debugstr_w(lpszDelim
),debugstr_w(lpszItem
),ppmk
);
1002 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
1004 if (!newItemMoniker
)
1005 return STG_E_INSUFFICIENTMEMORY
;
1007 hr
= ItemMonikerImpl_Construct(newItemMoniker
,lpszDelim
,lpszItem
);
1011 HeapFree(GetProcessHeap(),0,newItemMoniker
);
1015 return ItemMonikerImpl_QueryInterface((IMoniker
*)newItemMoniker
,&IID_IMoniker
,(void**)ppmk
);
1018 static HRESULT WINAPI
ItemMonikerCF_QueryInterface(LPCLASSFACTORY iface
,
1019 REFIID riid
, LPVOID
*ppv
)
1022 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
))
1025 IUnknown_AddRef(iface
);
1028 return E_NOINTERFACE
;
1031 static ULONG WINAPI
ItemMonikerCF_AddRef(LPCLASSFACTORY iface
)
1033 return 2; /* non-heap based object */
1036 static ULONG WINAPI
ItemMonikerCF_Release(LPCLASSFACTORY iface
)
1038 return 1; /* non-heap based object */
1041 static HRESULT WINAPI
ItemMonikerCF_CreateInstance(LPCLASSFACTORY iface
,
1042 LPUNKNOWN pUnk
, REFIID riid
, LPVOID
*ppv
)
1044 ItemMonikerImpl
* newItemMoniker
;
1046 static const WCHAR wszEmpty
[] = { 0 };
1048 TRACE("(%p, %s, %p)\n", pUnk
, debugstr_guid(riid
), ppv
);
1053 return CLASS_E_NOAGGREGATION
;
1055 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
1056 if (!newItemMoniker
)
1057 return E_OUTOFMEMORY
;
1059 hr
= ItemMonikerImpl_Construct(newItemMoniker
, wszEmpty
, wszEmpty
);
1062 hr
= ItemMonikerImpl_QueryInterface((IMoniker
*)newItemMoniker
, riid
, ppv
);
1064 HeapFree(GetProcessHeap(),0,newItemMoniker
);
1069 static HRESULT WINAPI
ItemMonikerCF_LockServer(LPCLASSFACTORY iface
, BOOL fLock
)
1071 FIXME("(%d), stub!\n",fLock
);
1075 static const IClassFactoryVtbl ItemMonikerCFVtbl
=
1077 ItemMonikerCF_QueryInterface
,
1078 ItemMonikerCF_AddRef
,
1079 ItemMonikerCF_Release
,
1080 ItemMonikerCF_CreateInstance
,
1081 ItemMonikerCF_LockServer
1083 static const IClassFactoryVtbl
*ItemMonikerCF
= &ItemMonikerCFVtbl
;
1085 HRESULT
ItemMonikerCF_Create(REFIID riid
, LPVOID
*ppv
)
1087 return IClassFactory_QueryInterface((IClassFactory
*)&ItemMonikerCF
, riid
, ppv
);