1 /***************************************************************************************
2 * ItemMonikers implementation
4 * Copyright 1999 Noomen Hamza
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ***************************************************************************************/
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
36 #include "wine/unicode.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
41 const CLSID CLSID_ItemMoniker
= {
42 0x304, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
45 /* ItemMoniker data structure */
46 typedef struct ItemMonikerImpl
{
48 IMonikerVtbl
* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
50 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
51 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
53 IROTDataVtbl
* lpvtbl2
; /* VTable relative to the IROTData interface.*/
55 ULONG ref
; /* reference counter for this object */
57 LPOLESTR itemName
; /* item name identified by this ItemMoniker */
59 LPOLESTR itemDelimiter
; /* Delimiter string */
61 IUnknown
*pMarshal
; /* custom marshaler */
64 /********************************************************************************/
65 /* ItemMoniker prototype functions : */
67 /* IUnknown prototype functions */
68 static HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
);
69 static ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
);
70 static ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
);
72 /* IPersist prototype functions */
73 static HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
, CLSID
*pClassID
);
75 /* IPersistStream prototype functions */
76 static HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
);
77 static HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
, IStream
* pStm
);
78 static HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
);
79 static HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
);
81 /* IMoniker prototype functions */
82 static HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
83 static HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
84 static HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,IBindCtx
* pbc
, DWORD dwReduceHowFar
,IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
);
85 static HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,IMoniker
* pmkRight
,BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
);
86 static HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
);
87 static HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
);
88 static HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
);
89 static HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, IMoniker
* pmkNewlyRunning
);
90 static HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
, FILETIME
* pItemTime
);
91 static HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
);
92 static HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
, IMoniker
** ppmkPrefix
);
93 static HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
);
94 static HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
);
95 static HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
);
96 static HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
);
98 /* Local function used by ItemMoniker implementation */
99 HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* iface
, LPCOLESTR lpszDelim
,LPCOLESTR lpszPathName
);
100 HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* iface
);
102 /********************************************************************************/
103 /* IROTData prototype functions */
105 /* IUnknown prototype functions */
106 static HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
* iface
,REFIID riid
,VOID
** ppvObject
);
107 static ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
* iface
);
108 static ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
);
110 /* IROTData prototype function */
111 static HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparisonData(IROTData
* iface
,BYTE
* pbData
,ULONG cbMax
,ULONG
* pcbData
);
113 /********************************************************************************/
114 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
115 /* IPersistStream and IMoniker functions. */
116 static IMonikerVtbl VT_ItemMonikerImpl
=
118 ItemMonikerImpl_QueryInterface
,
119 ItemMonikerImpl_AddRef
,
120 ItemMonikerImpl_Release
,
121 ItemMonikerImpl_GetClassID
,
122 ItemMonikerImpl_IsDirty
,
123 ItemMonikerImpl_Load
,
124 ItemMonikerImpl_Save
,
125 ItemMonikerImpl_GetSizeMax
,
126 ItemMonikerImpl_BindToObject
,
127 ItemMonikerImpl_BindToStorage
,
128 ItemMonikerImpl_Reduce
,
129 ItemMonikerImpl_ComposeWith
,
130 ItemMonikerImpl_Enum
,
131 ItemMonikerImpl_IsEqual
,
132 ItemMonikerImpl_Hash
,
133 ItemMonikerImpl_IsRunning
,
134 ItemMonikerImpl_GetTimeOfLastChange
,
135 ItemMonikerImpl_Inverse
,
136 ItemMonikerImpl_CommonPrefixWith
,
137 ItemMonikerImpl_RelativePathTo
,
138 ItemMonikerImpl_GetDisplayName
,
139 ItemMonikerImpl_ParseDisplayName
,
140 ItemMonikerImpl_IsSystemMoniker
143 /********************************************************************************/
144 /* Virtual function table for the IROTData class. */
145 static IROTDataVtbl VT_ROTDataImpl
=
147 ItemMonikerROTDataImpl_QueryInterface
,
148 ItemMonikerROTDataImpl_AddRef
,
149 ItemMonikerROTDataImpl_Release
,
150 ItemMonikerROTDataImpl_GetComparisonData
153 /*******************************************************************************
154 * ItemMoniker_QueryInterface
155 *******************************************************************************/
156 HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
158 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
160 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppvObject
);
162 /* Perform a sanity check on the parameters.*/
163 if ( (This
==0) || (ppvObject
==0) )
166 /* Initialize the return parameter */
169 /* Compare the riid with the interface IDs implemented by this object.*/
170 if (IsEqualIID(&IID_IUnknown
, riid
) ||
171 IsEqualIID(&IID_IPersist
, riid
) ||
172 IsEqualIID(&IID_IPersistStream
, riid
) ||
173 IsEqualIID(&IID_IMoniker
, riid
)
177 else if (IsEqualIID(&IID_IROTData
, riid
))
178 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
179 else if (IsEqualIID(&IID_IMarshal
, riid
))
183 hr
= MonikerMarshal_Create(iface
, &This
->pMarshal
);
186 return IUnknown_QueryInterface(This
->pMarshal
, riid
, ppvObject
);
189 /* Check that we obtained an interface.*/
191 return E_NOINTERFACE
;
193 /* Query Interface always increases the reference count by one when it is successful */
194 ItemMonikerImpl_AddRef(iface
);
199 /******************************************************************************
201 ******************************************************************************/
202 ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
)
204 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
206 TRACE("(%p)\n",This
);
208 return InterlockedIncrement(&This
->ref
);
211 /******************************************************************************
212 * ItemMoniker_Release
213 ******************************************************************************/
214 ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
)
216 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
219 TRACE("(%p)\n",This
);
221 ref
= InterlockedDecrement(&This
->ref
);
223 /* destroy the object if there's no more reference on it */
224 if (ref
== 0) ItemMonikerImpl_Destroy(This
);
229 /******************************************************************************
230 * ItemMoniker_GetClassID
231 ******************************************************************************/
232 HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
234 TRACE("(%p,%p)\n",iface
,pClassID
);
239 *pClassID
= CLSID_ItemMoniker
;
244 /******************************************************************************
245 * ItemMoniker_IsDirty
246 ******************************************************************************/
247 HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
)
249 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
250 method in the OLE-provided moniker interfaces always return S_FALSE because
251 their internal state never changes. */
253 TRACE("(%p)\n",iface
);
258 /******************************************************************************
260 ******************************************************************************/
261 HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
264 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
266 DWORD delimiterLength
,nameLength
,lenW
;
267 CHAR
*itemNameA
,*itemDelimiterA
;
272 /* for more details about data read by this function see coments of ItemMonikerImpl_Save function */
274 /* read item delimiter string length + 1 */
275 res
=IStream_Read(pStm
,&delimiterLength
,sizeof(DWORD
),&bread
);
276 if (bread
!= sizeof(DWORD
))
279 /* read item delimiter string */
280 if (!(itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
)))
281 return E_OUTOFMEMORY
;
282 res
=IStream_Read(pStm
,itemDelimiterA
,delimiterLength
,&bread
);
283 if (bread
!= delimiterLength
)
285 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
289 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, NULL
, 0 );
290 This
->itemDelimiter
=HeapReAlloc(GetProcessHeap(),0,This
->itemDelimiter
,lenW
*sizeof(WCHAR
));
291 if (!This
->itemDelimiter
)
293 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
294 return E_OUTOFMEMORY
;
296 MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, This
->itemDelimiter
, lenW
);
297 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
299 /* read item name string length + 1*/
300 res
=IStream_Read(pStm
,&nameLength
,sizeof(DWORD
),&bread
);
301 if (bread
!= sizeof(DWORD
))
304 /* read item name string */
305 if (!(itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
)))
306 return E_OUTOFMEMORY
;
307 res
=IStream_Read(pStm
,itemNameA
,nameLength
,&bread
);
308 if (bread
!= nameLength
)
310 HeapFree( GetProcessHeap(), 0, itemNameA
);
314 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, NULL
, 0 );
315 This
->itemName
=HeapReAlloc(GetProcessHeap(),0,This
->itemName
,lenW
*sizeof(WCHAR
));
318 HeapFree( GetProcessHeap(), 0, itemNameA
);
319 return E_OUTOFMEMORY
;
321 MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, This
->itemName
, lenW
);
322 HeapFree( GetProcessHeap(), 0, itemNameA
);
327 /******************************************************************************
329 ******************************************************************************/
330 HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
,
331 IStream
* pStm
,/* pointer to the stream where the object is to be saved */
332 BOOL fClearDirty
)/* Specifies whether to clear the dirty flag */
334 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
336 CHAR
*itemNameA
,*itemDelimiterA
;
338 /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
339 /* 2) String (type A): item delimiter string ('\0' included) */
340 /* 3) DWORD : size of item name string ('\0' included) */
341 /* 4) String (type A): item name string ('\0' included) */
343 DWORD nameLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, NULL
, 0, NULL
, NULL
);
344 DWORD delimiterLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, NULL
, 0, NULL
, NULL
);
345 itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
);
346 itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
);
347 WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, itemNameA
, nameLength
, NULL
, NULL
);
348 WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, itemDelimiterA
, delimiterLength
, NULL
, NULL
);
350 TRACE("%p, %s\n", pStm
, fClearDirty
? "TRUE" : "FALSE");
352 res
=IStream_Write(pStm
,&delimiterLength
,sizeof(DWORD
),NULL
);
353 res
=IStream_Write(pStm
,itemDelimiterA
,delimiterLength
* sizeof(CHAR
),NULL
);
354 res
=IStream_Write(pStm
,&nameLength
,sizeof(DWORD
),NULL
);
355 res
=IStream_Write(pStm
,itemNameA
,nameLength
* sizeof(CHAR
),NULL
);
360 /******************************************************************************
361 * ItemMoniker_GetSizeMax
362 ******************************************************************************/
363 HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
,
364 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
366 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
367 DWORD delimiterLength
=lstrlenW(This
->itemDelimiter
)+1;
368 DWORD nameLength
=lstrlenW(This
->itemName
)+1;
370 TRACE("(%p,%p)\n",iface
,pcbSize
);
375 /* for more details see ItemMonikerImpl_Save coments */
377 pcbSize
->u
.LowPart
= sizeof(DWORD
) + /* DWORD which contains delimiter length */
378 delimiterLength
*4 + /* item delimiter string */
379 sizeof(DWORD
) + /* DWORD which contains item name length */
380 nameLength
*4 + /* item name string */
381 18; /* strange, but true */
382 pcbSize
->u
.HighPart
=0;
387 /******************************************************************************
388 * ItemMoniker_Construct (local function)
389 *******************************************************************************/
390 HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* This
, LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
)
393 int sizeStr1
=lstrlenW(lpszItem
), sizeStr2
;
394 static const OLECHAR emptystr
[1];
397 TRACE("(%p,%s,%s)\n",This
,debugstr_w(lpszDelim
),debugstr_w(lpszItem
));
399 /* Initialize the virtual fgunction table. */
400 This
->lpvtbl1
= &VT_ItemMonikerImpl
;
401 This
->lpvtbl2
= &VT_ROTDataImpl
;
403 This
->pMarshal
= NULL
;
405 This
->itemName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr1
+1));
407 return E_OUTOFMEMORY
;
408 lstrcpyW(This
->itemName
,lpszItem
);
411 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
413 delim
= lpszDelim
? lpszDelim
: emptystr
;
415 sizeStr2
=lstrlenW(delim
);
416 This
->itemDelimiter
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr2
+1));
417 if (!This
->itemDelimiter
) {
418 HeapFree(GetProcessHeap(),0,This
->itemName
);
419 return E_OUTOFMEMORY
;
421 lstrcpyW(This
->itemDelimiter
,delim
);
425 /******************************************************************************
426 * ItemMoniker_Destroy (local function)
427 *******************************************************************************/
428 HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* This
)
430 TRACE("(%p)\n",This
);
432 if (This
->pMarshal
) IUnknown_Release(This
->pMarshal
);
433 HeapFree(GetProcessHeap(),0,This
->itemName
);
434 HeapFree(GetProcessHeap(),0,This
->itemDelimiter
);
435 HeapFree(GetProcessHeap(),0,This
);
440 /******************************************************************************
441 * ItemMoniker_BindToObject
442 ******************************************************************************/
443 HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,
449 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
452 IID refid
=IID_IOleItemContainer
;
453 IOleItemContainer
*poic
=0;
455 TRACE("(%p,%p,%p,%s,%p)\n",iface
,pbc
,pmkToLeft
,debugstr_guid(riid
),ppvResult
);
465 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&refid
,(void**)&poic
);
469 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,riid
,ppvResult
);
471 IOleItemContainer_Release(poic
);
477 /******************************************************************************
478 * ItemMoniker_BindToStorage
479 ******************************************************************************/
480 HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,
486 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
489 IOleItemContainer
*poic
=0;
491 TRACE("(%p,%p,%p,%s,%p)\n",iface
,pbc
,pmkToLeft
,debugstr_guid(riid
),ppvResult
);
498 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
502 res
=IOleItemContainer_GetObjectStorage(poic
,This
->itemName
,pbc
,riid
,ppvResult
);
504 IOleItemContainer_Release(poic
);
510 /******************************************************************************
512 ******************************************************************************/
513 HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,
515 DWORD dwReduceHowFar
,
516 IMoniker
** ppmkToLeft
,
517 IMoniker
** ppmkReduced
)
519 TRACE("(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
521 if (ppmkReduced
==NULL
)
524 ItemMonikerImpl_AddRef(iface
);
528 return MK_S_REDUCED_TO_SELF
;
530 /******************************************************************************
531 * ItemMoniker_ComposeWith
532 ******************************************************************************/
533 HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,
535 BOOL fOnlyIfNotGeneric
,
536 IMoniker
** ppmkComposite
)
540 IEnumMoniker
* penumMk
=0;
541 IMoniker
*pmostLeftMk
=0;
542 IMoniker
* tempMkComposite
=0;
544 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
546 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
551 IMoniker_IsSystemMoniker(pmkRight
,&mkSys
);
553 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
554 if(mkSys
==MKSYS_ANTIMONIKER
)
558 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
559 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
561 if(mkSys
==MKSYS_GENERICCOMPOSITE
){
563 res
=IMoniker_Enum(pmkRight
,TRUE
,&penumMk
);
568 res
=IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
);
570 IMoniker_IsSystemMoniker(pmostLeftMk
,&mkSys2
);
572 if(mkSys2
==MKSYS_ANTIMONIKER
){
574 IMoniker_Release(pmostLeftMk
);
576 tempMkComposite
=iface
;
577 IMoniker_AddRef(iface
);
579 while(IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
)==S_OK
){
581 res
=CreateGenericComposite(tempMkComposite
,pmostLeftMk
,ppmkComposite
);
583 IMoniker_Release(tempMkComposite
);
584 IMoniker_Release(pmostLeftMk
);
586 tempMkComposite
=*ppmkComposite
;
587 IMoniker_AddRef(tempMkComposite
);
592 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
594 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
595 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
596 a NULL moniker and a return value of MK_E_NEEDGENERIC */
598 if (!fOnlyIfNotGeneric
)
599 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
602 return MK_E_NEEDGENERIC
;
605 /******************************************************************************
607 ******************************************************************************/
608 HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
610 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
612 if (ppenumMoniker
== NULL
)
615 *ppenumMoniker
= NULL
;
620 /******************************************************************************
621 * ItemMoniker_IsEqual
622 ******************************************************************************/
623 HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
627 LPOLESTR dispName1
,dispName2
;
629 HRESULT res
= S_FALSE
;
631 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
633 if (!pmkOtherMoniker
) return S_FALSE
;
636 /* check if both are ItemMoniker */
637 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker
,&clsid
))) return S_FALSE
;
638 if(!IsEqualCLSID(&clsid
,&CLSID_ItemMoniker
)) return S_FALSE
;
640 /* check if both displaynames are the same */
641 if(SUCCEEDED ((res
= CreateBindCtx(0,&bind
)))) {
642 if(SUCCEEDED (IMoniker_GetDisplayName(iface
,bind
,NULL
,&dispName1
))) {
643 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&dispName2
))) {
644 if(lstrcmpW(dispName1
,dispName2
)==0) res
= S_OK
;
645 CoTaskMemFree(dispName2
);
647 CoTaskMemFree(dispName1
);
653 /******************************************************************************
655 ******************************************************************************/
656 HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
658 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
660 int h
= 0,i
,skip
,len
;
667 val
= This
->itemName
;
671 for (i
= len
; i
> 0; i
--) {
672 h
= (h
* 37) + val
[off
++];
675 /* only sample some characters */
677 for (i
= len
; i
> 0; i
-= skip
, off
+= skip
) {
678 h
= (h
* 39) + val
[off
];
687 /******************************************************************************
688 * ItemMoniker_IsRunning
689 ******************************************************************************/
690 HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,
693 IMoniker
* pmkNewlyRunning
)
695 IRunningObjectTable
* rot
;
697 IOleItemContainer
*poic
=0;
698 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
700 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
702 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
703 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
705 if ((pmkNewlyRunning
!=NULL
)&&(IMoniker_IsEqual(pmkNewlyRunning
,iface
)==S_OK
))
711 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
716 res
= IRunningObjectTable_IsRunning(rot
,iface
);
718 IRunningObjectTable_Release(rot
);
722 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
723 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
724 /* passing the string contained within this moniker. */
726 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
730 res
=IOleItemContainer_IsRunning(poic
,This
->itemName
);
732 IOleItemContainer_Release(poic
);
739 /******************************************************************************
740 * ItemMoniker_GetTimeOfLastChange
741 ******************************************************************************/
742 HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
747 IRunningObjectTable
* rot
;
749 IMoniker
*compositeMk
;
751 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pItemTime
);
756 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
759 return MK_E_NOTBINDABLE
;
762 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
763 /* the time of last change. If the object is not in the ROT, the method calls */
764 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
766 res
=CreateGenericComposite(pmkToLeft
,iface
,&compositeMk
);
768 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
770 if (IRunningObjectTable_GetTimeOfLastChange(rot
,compositeMk
,pItemTime
)!=S_OK
)
772 res
=IMoniker_GetTimeOfLastChange(pmkToLeft
,pbc
,NULL
,pItemTime
);
774 IMoniker_Release(compositeMk
);
780 /******************************************************************************
781 * ItemMoniker_Inverse
782 ******************************************************************************/
783 HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
785 TRACE("(%p,%p)\n",iface
,ppmk
);
790 return CreateAntiMoniker(ppmk
);
793 /******************************************************************************
794 * ItemMoniker_CommonPrefixWith
795 ******************************************************************************/
796 HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
800 TRACE("(%p,%p)\n", pmkOther
, ppmkPrefix
);
802 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
803 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
804 /* to this moniker and returns MK_S_US */
806 if((mkSys
==MKSYS_ITEMMONIKER
) && (IMoniker_IsEqual(iface
,pmkOther
)==S_OK
) ){
810 IMoniker_AddRef(iface
);
815 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
816 /* the case where the other moniker is a generic composite. */
817 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
820 /******************************************************************************
821 * ItemMoniker_RelativePathTo
822 ******************************************************************************/
823 HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
825 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
827 if (ppmkRelPath
==NULL
)
832 return MK_E_NOTBINDABLE
;
835 /******************************************************************************
836 * ItemMoniker_GetDisplayName
837 ******************************************************************************/
838 HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,
841 LPOLESTR
*ppszDisplayName
)
843 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
845 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
847 if (ppszDisplayName
==NULL
)
850 if (pmkToLeft
!=NULL
){
854 *ppszDisplayName
=CoTaskMemAlloc(sizeof(WCHAR
)*(lstrlenW(This
->itemDelimiter
)+lstrlenW(This
->itemName
)+1));
856 if (*ppszDisplayName
==NULL
)
857 return E_OUTOFMEMORY
;
859 lstrcpyW(*ppszDisplayName
,This
->itemDelimiter
);
860 lstrcatW(*ppszDisplayName
,This
->itemName
);
862 TRACE("-- %s\n", debugstr_w(*ppszDisplayName
));
867 /******************************************************************************
868 * ItemMoniker_ParseDisplayName
869 ******************************************************************************/
870 HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,
873 LPOLESTR pszDisplayName
,
877 IOleItemContainer
* poic
=0;
878 IParseDisplayName
* ppdn
=0;
879 LPOLESTR displayName
;
881 ItemMonikerImpl
*This
= (ItemMonikerImpl
*)iface
;
883 TRACE("%s\n", debugstr_w(pszDisplayName
));
885 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
891 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
892 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
893 /* name to IParseDisplayName::ParseDisplayName */
894 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
898 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,&IID_IParseDisplayName
,(void**)&ppdn
);
900 res
=IMoniker_GetDisplayName(iface
,pbc
,NULL
,&displayName
);
902 res
=IParseDisplayName_ParseDisplayName(ppdn
,pbc
,displayName
,pchEaten
,ppmkOut
);
904 IOleItemContainer_Release(poic
);
905 IParseDisplayName_Release(ppdn
);
911 /******************************************************************************
912 * ItemMoniker_IsSystemMoniker
913 ******************************************************************************/
914 HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
916 TRACE("(%p,%p)\n",iface
,pwdMksys
);
921 (*pwdMksys
)=MKSYS_ITEMMONIKER
;
926 /*******************************************************************************
927 * ItemMonikerIROTData_QueryInterface
928 *******************************************************************************/
929 HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
932 ICOM_THIS_From_IROTData(IMoniker
, iface
);
934 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
936 return ItemMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
939 /***********************************************************************
940 * ItemMonikerIROTData_AddRef
942 ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
*iface
)
944 ICOM_THIS_From_IROTData(IMoniker
, iface
);
946 TRACE("(%p)\n",iface
);
948 return ItemMonikerImpl_AddRef(This
);
951 /***********************************************************************
952 * ItemMonikerIROTData_Release
954 ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
)
956 ICOM_THIS_From_IROTData(IMoniker
, iface
);
958 TRACE("(%p)\n",iface
);
960 return ItemMonikerImpl_Release(This
);
963 /******************************************************************************
964 * ItemMonikerIROTData_GetComparaisonData
965 ******************************************************************************/
966 HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparisonData(IROTData
* iface
,
971 ICOM_THIS_From_IROTData(IMoniker
, iface
);
972 ItemMonikerImpl
*This1
= (ItemMonikerImpl
*)This
;
973 int len
= (strlenW(This1
->itemName
)+1);
976 LPWSTR pszItemDelimiter
;
978 TRACE("(%p, %lu, %p)\n", pbData
, cbMax
, pcbData
);
980 *pcbData
= sizeof(CLSID
) + sizeof(WCHAR
) + len
* sizeof(WCHAR
);
981 if (cbMax
< *pcbData
)
982 return E_OUTOFMEMORY
;
985 memcpy(pbData
, &CLSID_ItemMoniker
, sizeof(CLSID
));
986 /* write delimiter */
987 pszItemDelimiter
= (LPWSTR
)(pbData
+sizeof(CLSID
));
988 *pszItemDelimiter
= *This1
->itemDelimiter
;
990 pszItemName
= pszItemDelimiter
+ 1;
991 for (i
= 0; i
< len
; i
++)
992 pszItemName
[i
] = toupperW(This1
->itemName
[i
]);
997 /******************************************************************************
998 * CreateItemMoniker [OLE32.@]
999 ******************************************************************************/
1000 HRESULT WINAPI
CreateItemMoniker(LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
, LPMONIKER
* ppmk
)
1002 ItemMonikerImpl
* newItemMoniker
;
1005 TRACE("(%s,%s,%p)\n",debugstr_w(lpszDelim
),debugstr_w(lpszItem
),ppmk
);
1007 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
1009 if (!newItemMoniker
)
1010 return STG_E_INSUFFICIENTMEMORY
;
1012 hr
= ItemMonikerImpl_Construct(newItemMoniker
,lpszDelim
,lpszItem
);
1016 HeapFree(GetProcessHeap(),0,newItemMoniker
);
1020 return ItemMonikerImpl_QueryInterface((IMoniker
*)newItemMoniker
,&IID_IMoniker
,(void**)ppmk
);
1023 static HRESULT WINAPI
ItemMonikerCF_QueryInterface(LPCLASSFACTORY iface
,
1024 REFIID riid
, LPVOID
*ppv
)
1027 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
))
1030 IUnknown_AddRef(iface
);
1033 return E_NOINTERFACE
;
1036 static ULONG WINAPI
ItemMonikerCF_AddRef(LPCLASSFACTORY iface
)
1038 return 2; /* non-heap based object */
1041 static ULONG WINAPI
ItemMonikerCF_Release(LPCLASSFACTORY iface
)
1043 return 1; /* non-heap based object */
1046 static HRESULT WINAPI
ItemMonikerCF_CreateInstance(LPCLASSFACTORY iface
,
1047 LPUNKNOWN pUnk
, REFIID riid
, LPVOID
*ppv
)
1049 ItemMonikerImpl
* newItemMoniker
;
1051 static const WCHAR wszEmpty
[] = { 0 };
1053 TRACE("(%p, %s, %p)\n", pUnk
, debugstr_guid(riid
), ppv
);
1058 return CLASS_E_NOAGGREGATION
;
1060 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
1061 if (!newItemMoniker
)
1062 return E_OUTOFMEMORY
;
1064 hr
= ItemMonikerImpl_Construct(newItemMoniker
, wszEmpty
, wszEmpty
);
1067 hr
= ItemMonikerImpl_QueryInterface((IMoniker
*)newItemMoniker
, riid
, ppv
);
1069 HeapFree(GetProcessHeap(),0,newItemMoniker
);
1074 static HRESULT WINAPI
ItemMonikerCF_LockServer(LPCLASSFACTORY iface
, BOOL fLock
)
1076 FIXME("(%d), stub!\n",fLock
);
1080 static const IClassFactoryVtbl ItemMonikerCFVtbl
=
1082 ItemMonikerCF_QueryInterface
,
1083 ItemMonikerCF_AddRef
,
1084 ItemMonikerCF_Release
,
1085 ItemMonikerCF_CreateInstance
,
1086 ItemMonikerCF_LockServer
1088 static const IClassFactoryVtbl
*ItemMonikerCF
= &ItemMonikerCFVtbl
;
1090 HRESULT
ItemMonikerCF_Create(REFIID riid
, LPVOID
*ppv
)
1092 return IClassFactory_QueryInterface((IClassFactory
*)&ItemMonikerCF
, riid
, ppv
);