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
23 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
25 /* ItemMoniker data structure */
26 typedef struct ItemMonikerImpl
{
27 IMoniker IMoniker_iface
; /* VTable relative to the IMoniker interface.*/
28 IROTData IROTData_iface
; /* VTable relative to the IROTData interface.*/
30 LPOLESTR itemName
; /* item name identified by this ItemMoniker */
31 LPOLESTR itemDelimiter
; /* Delimiter string */
32 IUnknown
*pMarshal
; /* custom marshaler */
35 static inline ItemMonikerImpl
*impl_from_IMoniker(IMoniker
*iface
)
37 return CONTAINING_RECORD(iface
, ItemMonikerImpl
, IMoniker_iface
);
40 static inline ItemMonikerImpl
*impl_from_IROTData(IROTData
*iface
)
42 return CONTAINING_RECORD(iface
, ItemMonikerImpl
, IROTData_iface
);
45 static HRESULT
ItemMonikerImpl_Destroy(ItemMonikerImpl
* iface
);
47 /*******************************************************************************
48 * ItemMoniker_QueryInterface
49 *******************************************************************************/
50 static HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
52 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
54 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppvObject
);
59 /* Compare the riid with the interface IDs implemented by this object.*/
60 if (IsEqualIID(&IID_IUnknown
, riid
) ||
61 IsEqualIID(&IID_IPersist
, riid
) ||
62 IsEqualIID(&IID_IPersistStream
, riid
) ||
63 IsEqualIID(&IID_IMoniker
, riid
))
65 else if (IsEqualIID(&IID_IROTData
, riid
))
66 *ppvObject
= &This
->IROTData_iface
;
67 else if (IsEqualIID(&IID_IMarshal
, riid
))
71 hr
= MonikerMarshal_Create(iface
, &This
->pMarshal
);
74 return IUnknown_QueryInterface(This
->pMarshal
, riid
, ppvObject
);
82 IMoniker_AddRef(iface
);
86 /******************************************************************************
88 ******************************************************************************/
89 static ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
)
91 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
95 return InterlockedIncrement(&This
->ref
);
98 /******************************************************************************
100 ******************************************************************************/
101 static ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
)
103 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
106 TRACE("(%p)\n",This
);
108 ref
= InterlockedDecrement(&This
->ref
);
110 /* destroy the object if there are no more references to it */
111 if (ref
== 0) ItemMonikerImpl_Destroy(This
);
116 /******************************************************************************
117 * ItemMoniker_GetClassID
118 ******************************************************************************/
119 static HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
121 TRACE("(%p,%p)\n",iface
,pClassID
);
126 *pClassID
= CLSID_ItemMoniker
;
131 /******************************************************************************
132 * ItemMoniker_IsDirty
133 ******************************************************************************/
134 static HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
)
136 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
137 method in the OLE-provided moniker interfaces always return S_FALSE because
138 their internal state never changes. */
140 TRACE("(%p)\n",iface
);
145 /******************************************************************************
147 ******************************************************************************/
148 static HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
150 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
152 DWORD delimiterLength
,nameLength
,lenW
;
153 CHAR
*itemNameA
,*itemDelimiterA
;
158 /* for more details about data read by this function see comments of ItemMonikerImpl_Save function */
160 /* read item delimiter string length + 1 */
161 res
=IStream_Read(pStm
,&delimiterLength
,sizeof(DWORD
),&bread
);
162 if (bread
!= sizeof(DWORD
))
165 /* read item delimiter string */
166 if (!(itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
)))
167 return E_OUTOFMEMORY
;
168 res
=IStream_Read(pStm
,itemDelimiterA
,delimiterLength
,&bread
);
169 if (bread
!= delimiterLength
)
171 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
175 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, NULL
, 0 );
176 This
->itemDelimiter
=HeapReAlloc(GetProcessHeap(),0,This
->itemDelimiter
,lenW
*sizeof(WCHAR
));
177 if (!This
->itemDelimiter
)
179 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
180 return E_OUTOFMEMORY
;
182 MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, This
->itemDelimiter
, lenW
);
183 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
185 /* read item name string length + 1*/
186 res
=IStream_Read(pStm
,&nameLength
,sizeof(DWORD
),&bread
);
187 if (bread
!= sizeof(DWORD
))
190 /* read item name string */
191 if (!(itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
)))
192 return E_OUTOFMEMORY
;
193 res
=IStream_Read(pStm
,itemNameA
,nameLength
,&bread
);
194 if (bread
!= nameLength
)
196 HeapFree( GetProcessHeap(), 0, itemNameA
);
200 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, NULL
, 0 );
201 This
->itemName
=HeapReAlloc(GetProcessHeap(),0,This
->itemName
,lenW
*sizeof(WCHAR
));
204 HeapFree( GetProcessHeap(), 0, itemNameA
);
205 return E_OUTOFMEMORY
;
207 MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, This
->itemName
, lenW
);
208 HeapFree( GetProcessHeap(), 0, itemNameA
);
213 /******************************************************************************
215 ******************************************************************************/
216 static HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
)
218 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
220 CHAR
*itemNameA
,*itemDelimiterA
;
222 /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
223 /* 2) String (type A): item delimiter string ('\0' included) */
224 /* 3) DWORD : size of item name string ('\0' included) */
225 /* 4) String (type A): item name string ('\0' included) */
227 DWORD nameLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, NULL
, 0, NULL
, NULL
);
228 DWORD delimiterLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, NULL
, 0, NULL
, NULL
);
229 itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
);
230 itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
);
231 WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, itemNameA
, nameLength
, NULL
, NULL
);
232 WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, itemDelimiterA
, delimiterLength
, NULL
, NULL
);
234 TRACE("%p, %s\n", pStm
, fClearDirty
? "TRUE" : "FALSE");
236 res
=IStream_Write(pStm
,&delimiterLength
,sizeof(DWORD
),NULL
);
237 res
=IStream_Write(pStm
,itemDelimiterA
,delimiterLength
* sizeof(CHAR
),NULL
);
238 res
=IStream_Write(pStm
,&nameLength
,sizeof(DWORD
),NULL
);
239 res
=IStream_Write(pStm
,itemNameA
,nameLength
* sizeof(CHAR
),NULL
);
241 HeapFree(GetProcessHeap(), 0, itemNameA
);
242 HeapFree(GetProcessHeap(), 0, itemDelimiterA
);
247 /******************************************************************************
248 * ItemMoniker_GetSizeMax
249 ******************************************************************************/
250 static HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
)
252 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
253 DWORD delimiterLength
=lstrlenW(This
->itemDelimiter
)+1;
254 DWORD nameLength
=lstrlenW(This
->itemName
)+1;
256 TRACE("(%p,%p)\n",iface
,pcbSize
);
261 /* for more details see ItemMonikerImpl_Save comments */
263 pcbSize
->u
.LowPart
= sizeof(DWORD
) + /* DWORD which contains delimiter length */
264 delimiterLength
*4 + /* item delimiter string */
265 sizeof(DWORD
) + /* DWORD which contains item name length */
266 nameLength
*4 + /* item name string */
267 18; /* strange, but true */
268 pcbSize
->u
.HighPart
=0;
273 /******************************************************************************
274 * ItemMoniker_BindToObject
275 ******************************************************************************/
276 static HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,
282 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
284 IID refid
=IID_IOleItemContainer
;
285 IOleItemContainer
*poic
=0;
287 TRACE("(%p,%p,%p,%s,%p)\n",iface
,pbc
,pmkToLeft
,debugstr_guid(riid
),ppvResult
);
297 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&refid
,(void**)&poic
);
301 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,riid
,ppvResult
);
303 IOleItemContainer_Release(poic
);
309 /******************************************************************************
310 * ItemMoniker_BindToStorage
311 ******************************************************************************/
312 static HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,
318 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
320 IOleItemContainer
*poic
=0;
322 TRACE("(%p,%p,%p,%s,%p)\n",iface
,pbc
,pmkToLeft
,debugstr_guid(riid
),ppvResult
);
329 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
333 res
=IOleItemContainer_GetObjectStorage(poic
,This
->itemName
,pbc
,riid
,ppvResult
);
335 IOleItemContainer_Release(poic
);
341 /******************************************************************************
343 ******************************************************************************/
344 static HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,
346 DWORD dwReduceHowFar
,
347 IMoniker
** ppmkToLeft
,
348 IMoniker
** ppmkReduced
)
350 TRACE("(%p,%p,%d,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
352 if (ppmkReduced
==NULL
)
355 ItemMonikerImpl_AddRef(iface
);
359 return MK_S_REDUCED_TO_SELF
;
361 /******************************************************************************
362 * ItemMoniker_ComposeWith
363 ******************************************************************************/
364 static HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,
366 BOOL fOnlyIfNotGeneric
,
367 IMoniker
** ppmkComposite
)
371 IEnumMoniker
* penumMk
=0;
372 IMoniker
*pmostLeftMk
=0;
373 IMoniker
* tempMkComposite
=0;
375 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
377 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
382 IMoniker_IsSystemMoniker(pmkRight
,&mkSys
);
384 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
385 if(mkSys
==MKSYS_ANTIMONIKER
)
389 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
390 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
392 if(mkSys
==MKSYS_GENERICCOMPOSITE
){
394 res
=IMoniker_Enum(pmkRight
,TRUE
,&penumMk
);
399 res
=IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
);
401 IMoniker_IsSystemMoniker(pmostLeftMk
,&mkSys2
);
403 if(mkSys2
==MKSYS_ANTIMONIKER
){
405 IMoniker_Release(pmostLeftMk
);
407 tempMkComposite
=iface
;
408 IMoniker_AddRef(iface
);
410 while(IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
)==S_OK
){
412 res
=CreateGenericComposite(tempMkComposite
,pmostLeftMk
,ppmkComposite
);
414 IMoniker_Release(tempMkComposite
);
415 IMoniker_Release(pmostLeftMk
);
417 tempMkComposite
=*ppmkComposite
;
418 IMoniker_AddRef(tempMkComposite
);
423 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
425 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
426 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
427 a NULL moniker and a return value of MK_E_NEEDGENERIC */
429 if (!fOnlyIfNotGeneric
)
430 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
433 return MK_E_NEEDGENERIC
;
436 /******************************************************************************
438 ******************************************************************************/
439 static HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
441 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
443 if (ppenumMoniker
== NULL
)
446 *ppenumMoniker
= NULL
;
451 /******************************************************************************
452 * ItemMoniker_IsEqual
453 ******************************************************************************/
454 static HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
458 LPOLESTR dispName1
,dispName2
;
460 HRESULT res
= S_FALSE
;
462 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
464 if (!pmkOtherMoniker
) return S_FALSE
;
467 /* check if both are ItemMoniker */
468 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker
,&clsid
))) return S_FALSE
;
469 if(!IsEqualCLSID(&clsid
,&CLSID_ItemMoniker
)) return S_FALSE
;
471 /* check if both displaynames are the same */
472 if(SUCCEEDED ((res
= CreateBindCtx(0,&bind
)))) {
473 if(SUCCEEDED (IMoniker_GetDisplayName(iface
,bind
,NULL
,&dispName1
))) {
474 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&dispName2
))) {
475 if(lstrcmpW(dispName1
,dispName2
)==0) res
= S_OK
;
476 CoTaskMemFree(dispName2
);
478 CoTaskMemFree(dispName1
);
484 /******************************************************************************
486 ******************************************************************************/
487 static HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
489 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
498 val
= This
->itemName
;
501 for (i
= len
; i
> 0; i
--)
502 h
= (h
* 3) ^ toupperW(val
[off
++]);
509 /******************************************************************************
510 * ItemMoniker_IsRunning
511 ******************************************************************************/
512 static HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,
515 IMoniker
* pmkNewlyRunning
)
517 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
518 IRunningObjectTable
* rot
;
520 IOleItemContainer
*poic
=0;
522 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
524 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
525 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
527 if ((pmkNewlyRunning
!=NULL
)&&(IMoniker_IsEqual(pmkNewlyRunning
,iface
)==S_OK
))
533 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
538 res
= IRunningObjectTable_IsRunning(rot
,iface
);
540 IRunningObjectTable_Release(rot
);
544 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
545 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
546 /* passing the string contained within this moniker. */
548 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
552 res
=IOleItemContainer_IsRunning(poic
,This
->itemName
);
554 IOleItemContainer_Release(poic
);
561 /******************************************************************************
562 * ItemMoniker_GetTimeOfLastChange
563 ******************************************************************************/
564 static HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
569 IRunningObjectTable
* rot
;
571 IMoniker
*compositeMk
;
573 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pItemTime
);
578 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
581 return MK_E_NOTBINDABLE
;
584 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
585 /* the time of last change. If the object is not in the ROT, the method calls */
586 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
588 res
=CreateGenericComposite(pmkToLeft
,iface
,&compositeMk
);
592 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
594 IMoniker_Release(compositeMk
);
598 if (IRunningObjectTable_GetTimeOfLastChange(rot
,compositeMk
,pItemTime
)!=S_OK
)
600 res
=IMoniker_GetTimeOfLastChange(pmkToLeft
,pbc
,NULL
,pItemTime
);
602 IMoniker_Release(compositeMk
);
608 /******************************************************************************
609 * ItemMoniker_Inverse
610 ******************************************************************************/
611 static HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
613 TRACE("(%p,%p)\n",iface
,ppmk
);
618 return CreateAntiMoniker(ppmk
);
621 /******************************************************************************
622 * ItemMoniker_CommonPrefixWith
623 ******************************************************************************/
624 static HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
628 TRACE("(%p,%p)\n", pmkOther
, ppmkPrefix
);
630 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
631 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
632 /* to this moniker and returns MK_S_US */
634 if((mkSys
==MKSYS_ITEMMONIKER
) && (IMoniker_IsEqual(iface
,pmkOther
)==S_OK
) ){
638 IMoniker_AddRef(iface
);
643 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
644 /* the case where the other moniker is a generic composite. */
645 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
648 /******************************************************************************
649 * ItemMoniker_RelativePathTo
650 ******************************************************************************/
651 static HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
653 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
655 if (ppmkRelPath
==NULL
)
660 return MK_E_NOTBINDABLE
;
663 /******************************************************************************
664 * ItemMoniker_GetDisplayName
665 ******************************************************************************/
666 static HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,
669 LPOLESTR
*ppszDisplayName
)
671 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
673 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
675 if (ppszDisplayName
==NULL
)
678 if (pmkToLeft
!=NULL
){
682 *ppszDisplayName
=CoTaskMemAlloc(sizeof(WCHAR
)*(lstrlenW(This
->itemDelimiter
)+lstrlenW(This
->itemName
)+1));
684 if (*ppszDisplayName
==NULL
)
685 return E_OUTOFMEMORY
;
687 lstrcpyW(*ppszDisplayName
,This
->itemDelimiter
);
688 lstrcatW(*ppszDisplayName
,This
->itemName
);
690 TRACE("-- %s\n", debugstr_w(*ppszDisplayName
));
695 /******************************************************************************
696 * ItemMoniker_ParseDisplayName
697 ******************************************************************************/
698 static HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,
701 LPOLESTR pszDisplayName
,
705 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
706 IOleItemContainer
* poic
=0;
707 IParseDisplayName
* ppdn
=0;
708 LPOLESTR displayName
;
711 TRACE("%s\n", debugstr_w(pszDisplayName
));
713 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
719 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
720 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
721 /* name to IParseDisplayName::ParseDisplayName */
722 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
726 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,&IID_IParseDisplayName
,(void**)&ppdn
);
728 res
=IMoniker_GetDisplayName(iface
,pbc
,NULL
,&displayName
);
730 res
=IParseDisplayName_ParseDisplayName(ppdn
,pbc
,displayName
,pchEaten
,ppmkOut
);
732 IOleItemContainer_Release(poic
);
733 IParseDisplayName_Release(ppdn
);
739 /******************************************************************************
740 * ItemMoniker_IsSystemMoniker
741 ******************************************************************************/
742 static HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
744 TRACE("(%p,%p)\n",iface
,pwdMksys
);
749 (*pwdMksys
)=MKSYS_ITEMMONIKER
;
754 /*******************************************************************************
755 * ItemMonikerIROTData_QueryInterface
756 *******************************************************************************/
757 static HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,
761 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
763 TRACE("(%p,%s,%p)\n",iface
,debugstr_guid(riid
),ppvObject
);
765 return ItemMonikerImpl_QueryInterface(&This
->IMoniker_iface
, riid
, ppvObject
);
768 /***********************************************************************
769 * ItemMonikerIROTData_AddRef
771 static ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
*iface
)
773 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
775 TRACE("(%p)\n",iface
);
777 return ItemMonikerImpl_AddRef(&This
->IMoniker_iface
);
780 /***********************************************************************
781 * ItemMonikerIROTData_Release
783 static ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
)
785 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
787 TRACE("(%p)\n",iface
);
789 return ItemMonikerImpl_Release(&This
->IMoniker_iface
);
792 /******************************************************************************
793 * ItemMonikerIROTData_GetComparisonData
794 ******************************************************************************/
795 static HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparisonData(IROTData
* iface
,
800 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
801 int len
= (strlenW(This
->itemName
)+1);
804 LPWSTR pszItemDelimiter
;
806 TRACE("(%p, %u, %p)\n", pbData
, cbMax
, pcbData
);
808 *pcbData
= sizeof(CLSID
) + sizeof(WCHAR
) + len
* sizeof(WCHAR
);
809 if (cbMax
< *pcbData
)
810 return E_OUTOFMEMORY
;
813 memcpy(pbData
, &CLSID_ItemMoniker
, sizeof(CLSID
));
814 /* write delimiter */
815 pszItemDelimiter
= (LPWSTR
)(pbData
+sizeof(CLSID
));
816 *pszItemDelimiter
= *This
->itemDelimiter
;
818 pszItemName
= pszItemDelimiter
+ 1;
819 for (i
= 0; i
< len
; i
++)
820 pszItemName
[i
] = toupperW(This
->itemName
[i
]);
825 /********************************************************************************/
826 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
827 /* IPersistStream and IMoniker functions. */
828 static const IMonikerVtbl VT_ItemMonikerImpl
=
830 ItemMonikerImpl_QueryInterface
,
831 ItemMonikerImpl_AddRef
,
832 ItemMonikerImpl_Release
,
833 ItemMonikerImpl_GetClassID
,
834 ItemMonikerImpl_IsDirty
,
835 ItemMonikerImpl_Load
,
836 ItemMonikerImpl_Save
,
837 ItemMonikerImpl_GetSizeMax
,
838 ItemMonikerImpl_BindToObject
,
839 ItemMonikerImpl_BindToStorage
,
840 ItemMonikerImpl_Reduce
,
841 ItemMonikerImpl_ComposeWith
,
842 ItemMonikerImpl_Enum
,
843 ItemMonikerImpl_IsEqual
,
844 ItemMonikerImpl_Hash
,
845 ItemMonikerImpl_IsRunning
,
846 ItemMonikerImpl_GetTimeOfLastChange
,
847 ItemMonikerImpl_Inverse
,
848 ItemMonikerImpl_CommonPrefixWith
,
849 ItemMonikerImpl_RelativePathTo
,
850 ItemMonikerImpl_GetDisplayName
,
851 ItemMonikerImpl_ParseDisplayName
,
852 ItemMonikerImpl_IsSystemMoniker
855 /********************************************************************************/
856 /* Virtual function table for the IROTData class. */
857 static const IROTDataVtbl VT_ROTDataImpl
=
859 ItemMonikerROTDataImpl_QueryInterface
,
860 ItemMonikerROTDataImpl_AddRef
,
861 ItemMonikerROTDataImpl_Release
,
862 ItemMonikerROTDataImpl_GetComparisonData
865 /******************************************************************************
866 * ItemMoniker_Construct (local function)
867 *******************************************************************************/
868 static HRESULT
ItemMonikerImpl_Construct(ItemMonikerImpl
* This
, LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
)
871 int sizeStr1
=lstrlenW(lpszItem
), sizeStr2
;
872 static const OLECHAR emptystr
[1];
875 TRACE("(%p,%s,%s)\n",This
,debugstr_w(lpszDelim
),debugstr_w(lpszItem
));
877 /* Initialize the virtual function table. */
878 This
->IMoniker_iface
.lpVtbl
= &VT_ItemMonikerImpl
;
879 This
->IROTData_iface
.lpVtbl
= &VT_ROTDataImpl
;
881 This
->pMarshal
= NULL
;
883 This
->itemName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr1
+1));
885 return E_OUTOFMEMORY
;
886 lstrcpyW(This
->itemName
,lpszItem
);
889 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
891 delim
= lpszDelim
? lpszDelim
: emptystr
;
893 sizeStr2
=lstrlenW(delim
);
894 This
->itemDelimiter
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr2
+1));
895 if (!This
->itemDelimiter
) {
896 HeapFree(GetProcessHeap(),0,This
->itemName
);
897 return E_OUTOFMEMORY
;
899 lstrcpyW(This
->itemDelimiter
,delim
);
903 /******************************************************************************
904 * ItemMoniker_Destroy (local function)
905 *******************************************************************************/
906 static HRESULT
ItemMonikerImpl_Destroy(ItemMonikerImpl
* This
)
908 TRACE("(%p)\n",This
);
910 if (This
->pMarshal
) IUnknown_Release(This
->pMarshal
);
911 HeapFree(GetProcessHeap(),0,This
->itemName
);
912 HeapFree(GetProcessHeap(),0,This
->itemDelimiter
);
913 HeapFree(GetProcessHeap(),0,This
);
918 /******************************************************************************
919 * CreateItemMoniker [OLE32.@]
920 ******************************************************************************/
921 HRESULT WINAPI
CreateItemMoniker(LPCOLESTR lpszDelim
, LPCOLESTR lpszItem
, IMoniker
**ppmk
)
923 ItemMonikerImpl
* newItemMoniker
;
926 TRACE("(%s,%s,%p)\n",debugstr_w(lpszDelim
),debugstr_w(lpszItem
),ppmk
);
928 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
931 return STG_E_INSUFFICIENTMEMORY
;
933 hr
= ItemMonikerImpl_Construct(newItemMoniker
,lpszDelim
,lpszItem
);
936 HeapFree(GetProcessHeap(),0,newItemMoniker
);
940 return ItemMonikerImpl_QueryInterface(&newItemMoniker
->IMoniker_iface
,&IID_IMoniker
,
944 HRESULT WINAPI
ItemMoniker_CreateInstance(IClassFactory
*iface
,
945 IUnknown
*pUnk
, REFIID riid
, void **ppv
)
947 ItemMonikerImpl
* newItemMoniker
;
949 static const WCHAR wszEmpty
[] = { 0 };
951 TRACE("(%p, %s, %p)\n", pUnk
, debugstr_guid(riid
), ppv
);
956 return CLASS_E_NOAGGREGATION
;
958 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
960 return E_OUTOFMEMORY
;
962 hr
= ItemMonikerImpl_Construct(newItemMoniker
, wszEmpty
, wszEmpty
);
965 hr
= ItemMonikerImpl_QueryInterface(&newItemMoniker
->IMoniker_iface
, riid
, ppv
);
967 HeapFree(GetProcessHeap(),0,newItemMoniker
);