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
33 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
39 /* ItemMoniker data structure */
40 typedef struct ItemMonikerImpl
{
41 IMoniker IMoniker_iface
; /* VTable relative to the IMoniker interface.*/
42 IROTData IROTData_iface
; /* VTable relative to the IROTData interface.*/
44 LPOLESTR itemName
; /* item name identified by this ItemMoniker */
45 LPOLESTR itemDelimiter
; /* Delimiter string */
46 IUnknown
*pMarshal
; /* custom marshaler */
49 static inline ItemMonikerImpl
*impl_from_IMoniker(IMoniker
*iface
)
51 return CONTAINING_RECORD(iface
, ItemMonikerImpl
, IMoniker_iface
);
54 static inline ItemMonikerImpl
*impl_from_IROTData(IROTData
*iface
)
56 return CONTAINING_RECORD(iface
, ItemMonikerImpl
, IROTData_iface
);
59 static HRESULT
ItemMonikerImpl_Destroy(ItemMonikerImpl
* iface
);
61 /*******************************************************************************
62 * ItemMoniker_QueryInterface
63 *******************************************************************************/
64 static HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
66 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
68 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppvObject
);
73 /* Compare the riid with the interface IDs implemented by this object.*/
74 if (IsEqualIID(&IID_IUnknown
, riid
) ||
75 IsEqualIID(&IID_IPersist
, riid
) ||
76 IsEqualIID(&IID_IPersistStream
, riid
) ||
77 IsEqualIID(&IID_IMoniker
, riid
))
79 else if (IsEqualIID(&IID_IROTData
, riid
))
80 *ppvObject
= &This
->IROTData_iface
;
81 else if (IsEqualIID(&IID_IMarshal
, riid
))
85 hr
= MonikerMarshal_Create(iface
, &This
->pMarshal
);
88 return IUnknown_QueryInterface(This
->pMarshal
, riid
, ppvObject
);
96 IMoniker_AddRef(iface
);
100 /******************************************************************************
102 ******************************************************************************/
103 static ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
)
105 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
107 TRACE("(%p)\n",This
);
109 return InterlockedIncrement(&This
->ref
);
112 /******************************************************************************
113 * ItemMoniker_Release
114 ******************************************************************************/
115 static ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
)
117 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
120 TRACE("(%p)\n",This
);
122 ref
= InterlockedDecrement(&This
->ref
);
124 /* destroy the object if there are no more references to it */
125 if (ref
== 0) ItemMonikerImpl_Destroy(This
);
130 /******************************************************************************
131 * ItemMoniker_GetClassID
132 ******************************************************************************/
133 static HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
135 TRACE("(%p,%p)\n",iface
,pClassID
);
140 *pClassID
= CLSID_ItemMoniker
;
145 /******************************************************************************
146 * ItemMoniker_IsDirty
147 ******************************************************************************/
148 static HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
)
150 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
151 method in the OLE-provided moniker interfaces always return S_FALSE because
152 their internal state never changes. */
154 TRACE("(%p)\n",iface
);
159 /******************************************************************************
161 ******************************************************************************/
162 static HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
164 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
166 DWORD delimiterLength
,nameLength
,lenW
;
167 CHAR
*itemNameA
,*itemDelimiterA
;
172 /* for more details about data read by this function see comments of ItemMonikerImpl_Save function */
174 /* read item delimiter string length + 1 */
175 res
=IStream_Read(pStm
,&delimiterLength
,sizeof(DWORD
),&bread
);
176 if (bread
!= sizeof(DWORD
))
179 /* read item delimiter string */
180 if (!(itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
)))
181 return E_OUTOFMEMORY
;
182 res
=IStream_Read(pStm
,itemDelimiterA
,delimiterLength
,&bread
);
183 if (bread
!= delimiterLength
)
185 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
189 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, NULL
, 0 );
190 This
->itemDelimiter
=HeapReAlloc(GetProcessHeap(),0,This
->itemDelimiter
,lenW
*sizeof(WCHAR
));
191 if (!This
->itemDelimiter
)
193 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
194 return E_OUTOFMEMORY
;
196 MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, This
->itemDelimiter
, lenW
);
197 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
199 /* read item name string length + 1*/
200 res
=IStream_Read(pStm
,&nameLength
,sizeof(DWORD
),&bread
);
201 if (bread
!= sizeof(DWORD
))
204 /* read item name string */
205 if (!(itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
)))
206 return E_OUTOFMEMORY
;
207 res
=IStream_Read(pStm
,itemNameA
,nameLength
,&bread
);
208 if (bread
!= nameLength
)
210 HeapFree( GetProcessHeap(), 0, itemNameA
);
214 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, NULL
, 0 );
215 This
->itemName
=HeapReAlloc(GetProcessHeap(),0,This
->itemName
,lenW
*sizeof(WCHAR
));
218 HeapFree( GetProcessHeap(), 0, itemNameA
);
219 return E_OUTOFMEMORY
;
221 MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, This
->itemName
, lenW
);
222 HeapFree( GetProcessHeap(), 0, itemNameA
);
227 /******************************************************************************
229 ******************************************************************************/
230 static HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
)
232 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
234 CHAR
*itemNameA
,*itemDelimiterA
;
236 /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
237 /* 2) String (type A): item delimiter string ('\0' included) */
238 /* 3) DWORD : size of item name string ('\0' included) */
239 /* 4) String (type A): item name string ('\0' included) */
241 DWORD nameLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, NULL
, 0, NULL
, NULL
);
242 DWORD delimiterLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, NULL
, 0, NULL
, NULL
);
243 itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
);
244 itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
);
245 WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, itemNameA
, nameLength
, NULL
, NULL
);
246 WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, itemDelimiterA
, delimiterLength
, NULL
, NULL
);
248 TRACE("%p, %s\n", pStm
, fClearDirty
? "TRUE" : "FALSE");
250 res
=IStream_Write(pStm
,&delimiterLength
,sizeof(DWORD
),NULL
);
251 res
=IStream_Write(pStm
,itemDelimiterA
,delimiterLength
* sizeof(CHAR
),NULL
);
252 res
=IStream_Write(pStm
,&nameLength
,sizeof(DWORD
),NULL
);
253 res
=IStream_Write(pStm
,itemNameA
,nameLength
* sizeof(CHAR
),NULL
);
255 HeapFree(GetProcessHeap(), 0, itemNameA
);
256 HeapFree(GetProcessHeap(), 0, itemDelimiterA
);
261 /******************************************************************************
262 * ItemMoniker_GetSizeMax
263 ******************************************************************************/
264 static HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
)
266 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
267 DWORD delimiterLength
=lstrlenW(This
->itemDelimiter
)+1;
268 DWORD nameLength
=lstrlenW(This
->itemName
)+1;
270 TRACE("(%p,%p)\n",iface
,pcbSize
);
275 /* for more details see ItemMonikerImpl_Save comments */
277 pcbSize
->u
.LowPart
= sizeof(DWORD
) + /* DWORD which contains delimiter length */
278 delimiterLength
*4 + /* item delimiter string */
279 sizeof(DWORD
) + /* DWORD which contains item name length */
280 nameLength
*4 + /* item name string */
281 18; /* strange, but true */
282 pcbSize
->u
.HighPart
=0;
287 /******************************************************************************
288 * ItemMoniker_BindToObject
289 ******************************************************************************/
290 static HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,
296 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
298 IID refid
=IID_IOleItemContainer
;
299 IOleItemContainer
*poic
=0;
301 TRACE("(%p,%p,%p,%s,%p)\n",iface
,pbc
,pmkToLeft
,debugstr_guid(riid
),ppvResult
);
311 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&refid
,(void**)&poic
);
315 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,riid
,ppvResult
);
317 IOleItemContainer_Release(poic
);
323 /******************************************************************************
324 * ItemMoniker_BindToStorage
325 ******************************************************************************/
326 static HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,
332 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
334 IOleItemContainer
*poic
=0;
336 TRACE("(%p,%p,%p,%s,%p)\n",iface
,pbc
,pmkToLeft
,debugstr_guid(riid
),ppvResult
);
343 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
347 res
=IOleItemContainer_GetObjectStorage(poic
,This
->itemName
,pbc
,riid
,ppvResult
);
349 IOleItemContainer_Release(poic
);
355 /******************************************************************************
357 ******************************************************************************/
358 static HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,
360 DWORD dwReduceHowFar
,
361 IMoniker
** ppmkToLeft
,
362 IMoniker
** ppmkReduced
)
364 TRACE("(%p,%p,%d,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
366 if (ppmkReduced
==NULL
)
369 ItemMonikerImpl_AddRef(iface
);
373 return MK_S_REDUCED_TO_SELF
;
375 /******************************************************************************
376 * ItemMoniker_ComposeWith
377 ******************************************************************************/
378 static HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,
380 BOOL fOnlyIfNotGeneric
,
381 IMoniker
** ppmkComposite
)
385 IEnumMoniker
* penumMk
=0;
386 IMoniker
*pmostLeftMk
=0;
387 IMoniker
* tempMkComposite
=0;
389 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
391 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
396 IMoniker_IsSystemMoniker(pmkRight
,&mkSys
);
398 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
399 if(mkSys
==MKSYS_ANTIMONIKER
)
403 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
404 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
406 if(mkSys
==MKSYS_GENERICCOMPOSITE
){
408 res
=IMoniker_Enum(pmkRight
,TRUE
,&penumMk
);
413 res
=IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
);
415 IMoniker_IsSystemMoniker(pmostLeftMk
,&mkSys2
);
417 if(mkSys2
==MKSYS_ANTIMONIKER
){
419 IMoniker_Release(pmostLeftMk
);
421 tempMkComposite
=iface
;
422 IMoniker_AddRef(iface
);
424 while(IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
)==S_OK
){
426 res
=CreateGenericComposite(tempMkComposite
,pmostLeftMk
,ppmkComposite
);
428 IMoniker_Release(tempMkComposite
);
429 IMoniker_Release(pmostLeftMk
);
431 tempMkComposite
=*ppmkComposite
;
432 IMoniker_AddRef(tempMkComposite
);
437 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
439 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
440 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
441 a NULL moniker and a return value of MK_E_NEEDGENERIC */
443 if (!fOnlyIfNotGeneric
)
444 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
447 return MK_E_NEEDGENERIC
;
450 /******************************************************************************
452 ******************************************************************************/
453 static HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
455 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
457 if (ppenumMoniker
== NULL
)
460 *ppenumMoniker
= NULL
;
465 /******************************************************************************
466 * ItemMoniker_IsEqual
467 ******************************************************************************/
468 static HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
472 LPOLESTR dispName1
,dispName2
;
474 HRESULT res
= S_FALSE
;
476 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
478 if (!pmkOtherMoniker
) return S_FALSE
;
481 /* check if both are ItemMoniker */
482 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker
,&clsid
))) return S_FALSE
;
483 if(!IsEqualCLSID(&clsid
,&CLSID_ItemMoniker
)) return S_FALSE
;
485 /* check if both displaynames are the same */
486 if(SUCCEEDED ((res
= CreateBindCtx(0,&bind
)))) {
487 if(SUCCEEDED (IMoniker_GetDisplayName(iface
,bind
,NULL
,&dispName1
))) {
488 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&dispName2
))) {
489 if(wcscmp(dispName1
,dispName2
)==0) res
= S_OK
;
490 CoTaskMemFree(dispName2
);
492 CoTaskMemFree(dispName1
);
498 /******************************************************************************
500 ******************************************************************************/
501 static HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
503 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
512 val
= This
->itemName
;
515 for (i
= len
; i
> 0; i
--)
516 h
= (h
* 3) ^ towupper(val
[off
++]);
523 /******************************************************************************
524 * ItemMoniker_IsRunning
525 ******************************************************************************/
526 static HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,
529 IMoniker
* pmkNewlyRunning
)
531 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
532 IRunningObjectTable
* rot
;
534 IOleItemContainer
*poic
=0;
536 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
538 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
539 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
541 if ((pmkNewlyRunning
!=NULL
)&&(IMoniker_IsEqual(pmkNewlyRunning
,iface
)==S_OK
))
547 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
552 res
= IRunningObjectTable_IsRunning(rot
,iface
);
554 IRunningObjectTable_Release(rot
);
558 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
559 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
560 /* passing the string contained within this moniker. */
562 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
566 res
=IOleItemContainer_IsRunning(poic
,This
->itemName
);
568 IOleItemContainer_Release(poic
);
575 /******************************************************************************
576 * ItemMoniker_GetTimeOfLastChange
577 ******************************************************************************/
578 static HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
583 IRunningObjectTable
* rot
;
585 IMoniker
*compositeMk
;
587 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pItemTime
);
592 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
595 return MK_E_NOTBINDABLE
;
598 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
599 /* the time of last change. If the object is not in the ROT, the method calls */
600 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
602 res
=CreateGenericComposite(pmkToLeft
,iface
,&compositeMk
);
606 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
608 IMoniker_Release(compositeMk
);
612 if (IRunningObjectTable_GetTimeOfLastChange(rot
,compositeMk
,pItemTime
)!=S_OK
)
614 res
=IMoniker_GetTimeOfLastChange(pmkToLeft
,pbc
,NULL
,pItemTime
);
616 IMoniker_Release(compositeMk
);
622 /******************************************************************************
623 * ItemMoniker_Inverse
624 ******************************************************************************/
625 static HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
627 TRACE("(%p,%p)\n",iface
,ppmk
);
632 return CreateAntiMoniker(ppmk
);
635 /******************************************************************************
636 * ItemMoniker_CommonPrefixWith
637 ******************************************************************************/
638 static HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
642 TRACE("(%p,%p)\n", pmkOther
, ppmkPrefix
);
644 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
645 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
646 /* to this moniker and returns MK_S_US */
648 if((mkSys
==MKSYS_ITEMMONIKER
) && (IMoniker_IsEqual(iface
,pmkOther
)==S_OK
) ){
652 IMoniker_AddRef(iface
);
657 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
658 /* the case where the other moniker is a generic composite. */
659 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
662 /******************************************************************************
663 * ItemMoniker_RelativePathTo
664 ******************************************************************************/
665 static HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
667 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
669 if (ppmkRelPath
==NULL
)
674 return MK_E_NOTBINDABLE
;
677 /******************************************************************************
678 * ItemMoniker_GetDisplayName
679 ******************************************************************************/
680 static HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,
683 LPOLESTR
*ppszDisplayName
)
685 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
687 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
689 if (ppszDisplayName
==NULL
)
692 if (pmkToLeft
!=NULL
){
696 *ppszDisplayName
=CoTaskMemAlloc(sizeof(WCHAR
)*(lstrlenW(This
->itemDelimiter
)+lstrlenW(This
->itemName
)+1));
698 if (*ppszDisplayName
==NULL
)
699 return E_OUTOFMEMORY
;
701 lstrcpyW(*ppszDisplayName
,This
->itemDelimiter
);
702 lstrcatW(*ppszDisplayName
,This
->itemName
);
704 TRACE("-- %s\n", debugstr_w(*ppszDisplayName
));
709 /******************************************************************************
710 * ItemMoniker_ParseDisplayName
711 ******************************************************************************/
712 static HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,
715 LPOLESTR pszDisplayName
,
719 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
720 IOleItemContainer
* poic
=0;
721 IParseDisplayName
* ppdn
=0;
722 LPOLESTR displayName
;
725 TRACE("%s\n", debugstr_w(pszDisplayName
));
727 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
733 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
734 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
735 /* name to IParseDisplayName::ParseDisplayName */
736 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
740 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,&IID_IParseDisplayName
,(void**)&ppdn
);
742 res
=IMoniker_GetDisplayName(iface
,pbc
,NULL
,&displayName
);
744 res
=IParseDisplayName_ParseDisplayName(ppdn
,pbc
,displayName
,pchEaten
,ppmkOut
);
746 IOleItemContainer_Release(poic
);
747 IParseDisplayName_Release(ppdn
);
753 /******************************************************************************
754 * ItemMoniker_IsSystemMoniker
755 ******************************************************************************/
756 static HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
758 TRACE("(%p,%p)\n",iface
,pwdMksys
);
763 (*pwdMksys
)=MKSYS_ITEMMONIKER
;
768 /*******************************************************************************
769 * ItemMonikerIROTData_QueryInterface
770 *******************************************************************************/
771 static HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,
775 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
777 TRACE("(%p,%s,%p)\n",iface
,debugstr_guid(riid
),ppvObject
);
779 return ItemMonikerImpl_QueryInterface(&This
->IMoniker_iface
, riid
, ppvObject
);
782 /***********************************************************************
783 * ItemMonikerIROTData_AddRef
785 static ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
*iface
)
787 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
789 TRACE("(%p)\n",iface
);
791 return ItemMonikerImpl_AddRef(&This
->IMoniker_iface
);
794 /***********************************************************************
795 * ItemMonikerIROTData_Release
797 static ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
)
799 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
801 TRACE("(%p)\n",iface
);
803 return ItemMonikerImpl_Release(&This
->IMoniker_iface
);
806 /******************************************************************************
807 * ItemMonikerIROTData_GetComparisonData
808 ******************************************************************************/
809 static HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparisonData(IROTData
* iface
,
814 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
815 int len
= (lstrlenW(This
->itemName
)+1);
818 LPWSTR pszItemDelimiter
;
820 TRACE("(%p, %u, %p)\n", pbData
, cbMax
, pcbData
);
822 *pcbData
= sizeof(CLSID
) + sizeof(WCHAR
) + len
* sizeof(WCHAR
);
823 if (cbMax
< *pcbData
)
824 return E_OUTOFMEMORY
;
827 memcpy(pbData
, &CLSID_ItemMoniker
, sizeof(CLSID
));
828 /* write delimiter */
829 pszItemDelimiter
= (LPWSTR
)(pbData
+sizeof(CLSID
));
830 *pszItemDelimiter
= *This
->itemDelimiter
;
832 pszItemName
= pszItemDelimiter
+ 1;
833 for (i
= 0; i
< len
; i
++)
834 pszItemName
[i
] = towupper(This
->itemName
[i
]);
839 /********************************************************************************/
840 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
841 /* IPersistStream and IMoniker functions. */
842 static const IMonikerVtbl VT_ItemMonikerImpl
=
844 ItemMonikerImpl_QueryInterface
,
845 ItemMonikerImpl_AddRef
,
846 ItemMonikerImpl_Release
,
847 ItemMonikerImpl_GetClassID
,
848 ItemMonikerImpl_IsDirty
,
849 ItemMonikerImpl_Load
,
850 ItemMonikerImpl_Save
,
851 ItemMonikerImpl_GetSizeMax
,
852 ItemMonikerImpl_BindToObject
,
853 ItemMonikerImpl_BindToStorage
,
854 ItemMonikerImpl_Reduce
,
855 ItemMonikerImpl_ComposeWith
,
856 ItemMonikerImpl_Enum
,
857 ItemMonikerImpl_IsEqual
,
858 ItemMonikerImpl_Hash
,
859 ItemMonikerImpl_IsRunning
,
860 ItemMonikerImpl_GetTimeOfLastChange
,
861 ItemMonikerImpl_Inverse
,
862 ItemMonikerImpl_CommonPrefixWith
,
863 ItemMonikerImpl_RelativePathTo
,
864 ItemMonikerImpl_GetDisplayName
,
865 ItemMonikerImpl_ParseDisplayName
,
866 ItemMonikerImpl_IsSystemMoniker
869 /********************************************************************************/
870 /* Virtual function table for the IROTData class. */
871 static const IROTDataVtbl VT_ROTDataImpl
=
873 ItemMonikerROTDataImpl_QueryInterface
,
874 ItemMonikerROTDataImpl_AddRef
,
875 ItemMonikerROTDataImpl_Release
,
876 ItemMonikerROTDataImpl_GetComparisonData
879 /******************************************************************************
880 * ItemMoniker_Construct (local function)
881 *******************************************************************************/
882 static HRESULT
ItemMonikerImpl_Construct(ItemMonikerImpl
* This
, LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
)
885 int sizeStr1
=lstrlenW(lpszItem
), sizeStr2
;
886 static const OLECHAR emptystr
[1];
889 TRACE("(%p,%s,%s)\n",This
,debugstr_w(lpszDelim
),debugstr_w(lpszItem
));
891 /* Initialize the virtual function table. */
892 This
->IMoniker_iface
.lpVtbl
= &VT_ItemMonikerImpl
;
893 This
->IROTData_iface
.lpVtbl
= &VT_ROTDataImpl
;
895 This
->pMarshal
= NULL
;
897 This
->itemName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr1
+1));
899 return E_OUTOFMEMORY
;
900 lstrcpyW(This
->itemName
,lpszItem
);
903 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
905 delim
= lpszDelim
? lpszDelim
: emptystr
;
907 sizeStr2
=lstrlenW(delim
);
908 This
->itemDelimiter
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr2
+1));
909 if (!This
->itemDelimiter
) {
910 HeapFree(GetProcessHeap(),0,This
->itemName
);
911 return E_OUTOFMEMORY
;
913 lstrcpyW(This
->itemDelimiter
,delim
);
917 /******************************************************************************
918 * ItemMoniker_Destroy (local function)
919 *******************************************************************************/
920 static HRESULT
ItemMonikerImpl_Destroy(ItemMonikerImpl
* This
)
922 TRACE("(%p)\n",This
);
924 if (This
->pMarshal
) IUnknown_Release(This
->pMarshal
);
925 HeapFree(GetProcessHeap(),0,This
->itemName
);
926 HeapFree(GetProcessHeap(),0,This
->itemDelimiter
);
927 HeapFree(GetProcessHeap(),0,This
);
932 /******************************************************************************
933 * CreateItemMoniker [OLE32.@]
934 ******************************************************************************/
935 HRESULT WINAPI
CreateItemMoniker(LPCOLESTR lpszDelim
, LPCOLESTR lpszItem
, IMoniker
**ppmk
)
937 ItemMonikerImpl
* newItemMoniker
;
940 TRACE("(%s,%s,%p)\n",debugstr_w(lpszDelim
),debugstr_w(lpszItem
),ppmk
);
942 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
945 return STG_E_INSUFFICIENTMEMORY
;
947 hr
= ItemMonikerImpl_Construct(newItemMoniker
,lpszDelim
,lpszItem
);
950 HeapFree(GetProcessHeap(),0,newItemMoniker
);
954 return ItemMonikerImpl_QueryInterface(&newItemMoniker
->IMoniker_iface
,&IID_IMoniker
,
958 HRESULT WINAPI
ItemMoniker_CreateInstance(IClassFactory
*iface
,
959 IUnknown
*pUnk
, REFIID riid
, void **ppv
)
961 ItemMonikerImpl
* newItemMoniker
;
963 static const WCHAR wszEmpty
[] = { 0 };
965 TRACE("(%p, %s, %p)\n", pUnk
, debugstr_guid(riid
), ppv
);
970 return CLASS_E_NOAGGREGATION
;
972 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
974 return E_OUTOFMEMORY
;
976 hr
= ItemMonikerImpl_Construct(newItemMoniker
, wszEmpty
, wszEmpty
);
979 hr
= ItemMonikerImpl_QueryInterface(&newItemMoniker
->IMoniker_iface
, riid
, ppv
);
981 HeapFree(GetProcessHeap(),0,newItemMoniker
);