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"
35 #include "wine/unicode.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
40 /* ItemMoniker data structure */
41 typedef struct ItemMonikerImpl
{
42 IMoniker IMoniker_iface
; /* VTable relative to the IMoniker interface.*/
43 IROTData IROTData_iface
; /* VTable relative to the IROTData interface.*/
45 LPOLESTR itemName
; /* item name identified by this ItemMoniker */
46 LPOLESTR itemDelimiter
; /* Delimiter string */
47 IUnknown
*pMarshal
; /* custom marshaler */
50 static inline ItemMonikerImpl
*impl_from_IMoniker(IMoniker
*iface
)
52 return CONTAINING_RECORD(iface
, ItemMonikerImpl
, IMoniker_iface
);
55 static inline ItemMonikerImpl
*impl_from_IROTData(IROTData
*iface
)
57 return CONTAINING_RECORD(iface
, ItemMonikerImpl
, IROTData_iface
);
60 static HRESULT
ItemMonikerImpl_Destroy(ItemMonikerImpl
* iface
);
62 /*******************************************************************************
63 * ItemMoniker_QueryInterface
64 *******************************************************************************/
65 static HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
67 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
69 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppvObject
);
74 /* Compare the riid with the interface IDs implemented by this object.*/
75 if (IsEqualIID(&IID_IUnknown
, riid
) ||
76 IsEqualIID(&IID_IPersist
, riid
) ||
77 IsEqualIID(&IID_IPersistStream
, riid
) ||
78 IsEqualIID(&IID_IMoniker
, riid
))
80 else if (IsEqualIID(&IID_IROTData
, riid
))
81 *ppvObject
= &This
->IROTData_iface
;
82 else if (IsEqualIID(&IID_IMarshal
, riid
))
86 hr
= MonikerMarshal_Create(iface
, &This
->pMarshal
);
89 return IUnknown_QueryInterface(This
->pMarshal
, riid
, ppvObject
);
97 IMoniker_AddRef(iface
);
101 /******************************************************************************
103 ******************************************************************************/
104 static ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
)
106 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
108 TRACE("(%p)\n",This
);
110 return InterlockedIncrement(&This
->ref
);
113 /******************************************************************************
114 * ItemMoniker_Release
115 ******************************************************************************/
116 static ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
)
118 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
121 TRACE("(%p)\n",This
);
123 ref
= InterlockedDecrement(&This
->ref
);
125 /* destroy the object if there are no more references to it */
126 if (ref
== 0) ItemMonikerImpl_Destroy(This
);
131 /******************************************************************************
132 * ItemMoniker_GetClassID
133 ******************************************************************************/
134 static HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
136 TRACE("(%p,%p)\n",iface
,pClassID
);
141 *pClassID
= CLSID_ItemMoniker
;
146 /******************************************************************************
147 * ItemMoniker_IsDirty
148 ******************************************************************************/
149 static HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
)
151 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
152 method in the OLE-provided moniker interfaces always return S_FALSE because
153 their internal state never changes. */
155 TRACE("(%p)\n",iface
);
160 /******************************************************************************
162 ******************************************************************************/
163 static HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
165 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
167 DWORD delimiterLength
,nameLength
,lenW
;
168 CHAR
*itemNameA
,*itemDelimiterA
;
173 /* for more details about data read by this function see comments of ItemMonikerImpl_Save function */
175 /* read item delimiter string length + 1 */
176 res
=IStream_Read(pStm
,&delimiterLength
,sizeof(DWORD
),&bread
);
177 if (bread
!= sizeof(DWORD
))
180 /* read item delimiter string */
181 if (!(itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
)))
182 return E_OUTOFMEMORY
;
183 res
=IStream_Read(pStm
,itemDelimiterA
,delimiterLength
,&bread
);
184 if (bread
!= delimiterLength
)
186 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
190 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, NULL
, 0 );
191 This
->itemDelimiter
=HeapReAlloc(GetProcessHeap(),0,This
->itemDelimiter
,lenW
*sizeof(WCHAR
));
192 if (!This
->itemDelimiter
)
194 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
195 return E_OUTOFMEMORY
;
197 MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, This
->itemDelimiter
, lenW
);
198 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
200 /* read item name string length + 1*/
201 res
=IStream_Read(pStm
,&nameLength
,sizeof(DWORD
),&bread
);
202 if (bread
!= sizeof(DWORD
))
205 /* read item name string */
206 if (!(itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
)))
207 return E_OUTOFMEMORY
;
208 res
=IStream_Read(pStm
,itemNameA
,nameLength
,&bread
);
209 if (bread
!= nameLength
)
211 HeapFree( GetProcessHeap(), 0, itemNameA
);
215 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, NULL
, 0 );
216 This
->itemName
=HeapReAlloc(GetProcessHeap(),0,This
->itemName
,lenW
*sizeof(WCHAR
));
219 HeapFree( GetProcessHeap(), 0, itemNameA
);
220 return E_OUTOFMEMORY
;
222 MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, This
->itemName
, lenW
);
223 HeapFree( GetProcessHeap(), 0, itemNameA
);
228 /******************************************************************************
230 ******************************************************************************/
231 static HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
)
233 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
235 CHAR
*itemNameA
,*itemDelimiterA
;
237 /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
238 /* 2) String (type A): item delimiter string ('\0' included) */
239 /* 3) DWORD : size of item name string ('\0' included) */
240 /* 4) String (type A): item name string ('\0' included) */
242 DWORD nameLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, NULL
, 0, NULL
, NULL
);
243 DWORD delimiterLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, NULL
, 0, NULL
, NULL
);
244 itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
);
245 itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
);
246 WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, itemNameA
, nameLength
, NULL
, NULL
);
247 WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, itemDelimiterA
, delimiterLength
, NULL
, NULL
);
249 TRACE("%p, %s\n", pStm
, fClearDirty
? "TRUE" : "FALSE");
251 res
=IStream_Write(pStm
,&delimiterLength
,sizeof(DWORD
),NULL
);
252 res
=IStream_Write(pStm
,itemDelimiterA
,delimiterLength
* sizeof(CHAR
),NULL
);
253 res
=IStream_Write(pStm
,&nameLength
,sizeof(DWORD
),NULL
);
254 res
=IStream_Write(pStm
,itemNameA
,nameLength
* sizeof(CHAR
),NULL
);
256 HeapFree(GetProcessHeap(), 0, itemNameA
);
257 HeapFree(GetProcessHeap(), 0, itemDelimiterA
);
262 /******************************************************************************
263 * ItemMoniker_GetSizeMax
264 ******************************************************************************/
265 static HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
)
267 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
268 DWORD delimiterLength
=lstrlenW(This
->itemDelimiter
)+1;
269 DWORD nameLength
=lstrlenW(This
->itemName
)+1;
271 TRACE("(%p,%p)\n",iface
,pcbSize
);
276 /* for more details see ItemMonikerImpl_Save comments */
278 pcbSize
->u
.LowPart
= sizeof(DWORD
) + /* DWORD which contains delimiter length */
279 delimiterLength
*4 + /* item delimiter string */
280 sizeof(DWORD
) + /* DWORD which contains item name length */
281 nameLength
*4 + /* item name string */
282 18; /* strange, but true */
283 pcbSize
->u
.HighPart
=0;
288 /******************************************************************************
289 * ItemMoniker_BindToObject
290 ******************************************************************************/
291 static HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,
297 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
299 IID refid
=IID_IOleItemContainer
;
300 IOleItemContainer
*poic
=0;
302 TRACE("(%p,%p,%p,%s,%p)\n",iface
,pbc
,pmkToLeft
,debugstr_guid(riid
),ppvResult
);
312 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&refid
,(void**)&poic
);
316 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,riid
,ppvResult
);
318 IOleItemContainer_Release(poic
);
324 /******************************************************************************
325 * ItemMoniker_BindToStorage
326 ******************************************************************************/
327 static HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,
333 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
335 IOleItemContainer
*poic
=0;
337 TRACE("(%p,%p,%p,%s,%p)\n",iface
,pbc
,pmkToLeft
,debugstr_guid(riid
),ppvResult
);
344 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
348 res
=IOleItemContainer_GetObjectStorage(poic
,This
->itemName
,pbc
,riid
,ppvResult
);
350 IOleItemContainer_Release(poic
);
356 /******************************************************************************
358 ******************************************************************************/
359 static HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,
361 DWORD dwReduceHowFar
,
362 IMoniker
** ppmkToLeft
,
363 IMoniker
** ppmkReduced
)
365 TRACE("(%p,%p,%d,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
367 if (ppmkReduced
==NULL
)
370 ItemMonikerImpl_AddRef(iface
);
374 return MK_S_REDUCED_TO_SELF
;
376 /******************************************************************************
377 * ItemMoniker_ComposeWith
378 ******************************************************************************/
379 static HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,
381 BOOL fOnlyIfNotGeneric
,
382 IMoniker
** ppmkComposite
)
386 IEnumMoniker
* penumMk
=0;
387 IMoniker
*pmostLeftMk
=0;
388 IMoniker
* tempMkComposite
=0;
390 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
392 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
397 IMoniker_IsSystemMoniker(pmkRight
,&mkSys
);
399 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
400 if(mkSys
==MKSYS_ANTIMONIKER
)
404 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
405 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
407 if(mkSys
==MKSYS_GENERICCOMPOSITE
){
409 res
=IMoniker_Enum(pmkRight
,TRUE
,&penumMk
);
414 res
=IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
);
416 IMoniker_IsSystemMoniker(pmostLeftMk
,&mkSys2
);
418 if(mkSys2
==MKSYS_ANTIMONIKER
){
420 IMoniker_Release(pmostLeftMk
);
422 tempMkComposite
=iface
;
423 IMoniker_AddRef(iface
);
425 while(IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
)==S_OK
){
427 res
=CreateGenericComposite(tempMkComposite
,pmostLeftMk
,ppmkComposite
);
429 IMoniker_Release(tempMkComposite
);
430 IMoniker_Release(pmostLeftMk
);
432 tempMkComposite
=*ppmkComposite
;
433 IMoniker_AddRef(tempMkComposite
);
438 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
440 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
441 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
442 a NULL moniker and a return value of MK_E_NEEDGENERIC */
444 if (!fOnlyIfNotGeneric
)
445 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
448 return MK_E_NEEDGENERIC
;
451 /******************************************************************************
453 ******************************************************************************/
454 static HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
456 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
458 if (ppenumMoniker
== NULL
)
461 *ppenumMoniker
= NULL
;
466 /******************************************************************************
467 * ItemMoniker_IsEqual
468 ******************************************************************************/
469 static HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
473 LPOLESTR dispName1
,dispName2
;
475 HRESULT res
= S_FALSE
;
477 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
479 if (!pmkOtherMoniker
) return S_FALSE
;
482 /* check if both are ItemMoniker */
483 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker
,&clsid
))) return S_FALSE
;
484 if(!IsEqualCLSID(&clsid
,&CLSID_ItemMoniker
)) return S_FALSE
;
486 /* check if both displaynames are the same */
487 if(SUCCEEDED ((res
= CreateBindCtx(0,&bind
)))) {
488 if(SUCCEEDED (IMoniker_GetDisplayName(iface
,bind
,NULL
,&dispName1
))) {
489 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&dispName2
))) {
490 if(lstrcmpW(dispName1
,dispName2
)==0) res
= S_OK
;
491 CoTaskMemFree(dispName2
);
493 CoTaskMemFree(dispName1
);
499 /******************************************************************************
501 ******************************************************************************/
502 static HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
504 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
513 val
= This
->itemName
;
516 for (i
= len
; i
> 0; i
--)
517 h
= (h
* 3) ^ toupperW(val
[off
++]);
524 /******************************************************************************
525 * ItemMoniker_IsRunning
526 ******************************************************************************/
527 static HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,
530 IMoniker
* pmkNewlyRunning
)
532 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
533 IRunningObjectTable
* rot
;
535 IOleItemContainer
*poic
=0;
537 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
539 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
540 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
542 if ((pmkNewlyRunning
!=NULL
)&&(IMoniker_IsEqual(pmkNewlyRunning
,iface
)==S_OK
))
548 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
553 res
= IRunningObjectTable_IsRunning(rot
,iface
);
555 IRunningObjectTable_Release(rot
);
559 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
560 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
561 /* passing the string contained within this moniker. */
563 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
567 res
=IOleItemContainer_IsRunning(poic
,This
->itemName
);
569 IOleItemContainer_Release(poic
);
576 /******************************************************************************
577 * ItemMoniker_GetTimeOfLastChange
578 ******************************************************************************/
579 static HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
584 IRunningObjectTable
* rot
;
586 IMoniker
*compositeMk
;
588 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pItemTime
);
593 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
596 return MK_E_NOTBINDABLE
;
599 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
600 /* the time of last change. If the object is not in the ROT, the method calls */
601 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
603 res
=CreateGenericComposite(pmkToLeft
,iface
,&compositeMk
);
607 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
609 IMoniker_Release(compositeMk
);
613 if (IRunningObjectTable_GetTimeOfLastChange(rot
,compositeMk
,pItemTime
)!=S_OK
)
615 res
=IMoniker_GetTimeOfLastChange(pmkToLeft
,pbc
,NULL
,pItemTime
);
617 IMoniker_Release(compositeMk
);
623 /******************************************************************************
624 * ItemMoniker_Inverse
625 ******************************************************************************/
626 static HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
628 TRACE("(%p,%p)\n",iface
,ppmk
);
633 return CreateAntiMoniker(ppmk
);
636 /******************************************************************************
637 * ItemMoniker_CommonPrefixWith
638 ******************************************************************************/
639 static HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
643 TRACE("(%p,%p)\n", pmkOther
, ppmkPrefix
);
645 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
646 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
647 /* to this moniker and returns MK_S_US */
649 if((mkSys
==MKSYS_ITEMMONIKER
) && (IMoniker_IsEqual(iface
,pmkOther
)==S_OK
) ){
653 IMoniker_AddRef(iface
);
658 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
659 /* the case where the other moniker is a generic composite. */
660 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
663 /******************************************************************************
664 * ItemMoniker_RelativePathTo
665 ******************************************************************************/
666 static HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
668 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
670 if (ppmkRelPath
==NULL
)
675 return MK_E_NOTBINDABLE
;
678 /******************************************************************************
679 * ItemMoniker_GetDisplayName
680 ******************************************************************************/
681 static HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,
684 LPOLESTR
*ppszDisplayName
)
686 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
688 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
690 if (ppszDisplayName
==NULL
)
693 if (pmkToLeft
!=NULL
){
697 *ppszDisplayName
=CoTaskMemAlloc(sizeof(WCHAR
)*(lstrlenW(This
->itemDelimiter
)+lstrlenW(This
->itemName
)+1));
699 if (*ppszDisplayName
==NULL
)
700 return E_OUTOFMEMORY
;
702 lstrcpyW(*ppszDisplayName
,This
->itemDelimiter
);
703 lstrcatW(*ppszDisplayName
,This
->itemName
);
705 TRACE("-- %s\n", debugstr_w(*ppszDisplayName
));
710 /******************************************************************************
711 * ItemMoniker_ParseDisplayName
712 ******************************************************************************/
713 static HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,
716 LPOLESTR pszDisplayName
,
720 ItemMonikerImpl
*This
= impl_from_IMoniker(iface
);
721 IOleItemContainer
* poic
=0;
722 IParseDisplayName
* ppdn
=0;
723 LPOLESTR displayName
;
726 TRACE("%s\n", debugstr_w(pszDisplayName
));
728 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
734 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
735 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
736 /* name to IParseDisplayName::ParseDisplayName */
737 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
741 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,&IID_IParseDisplayName
,(void**)&ppdn
);
743 res
=IMoniker_GetDisplayName(iface
,pbc
,NULL
,&displayName
);
745 res
=IParseDisplayName_ParseDisplayName(ppdn
,pbc
,displayName
,pchEaten
,ppmkOut
);
747 IOleItemContainer_Release(poic
);
748 IParseDisplayName_Release(ppdn
);
754 /******************************************************************************
755 * ItemMoniker_IsSystemMoniker
756 ******************************************************************************/
757 static HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
759 TRACE("(%p,%p)\n",iface
,pwdMksys
);
764 (*pwdMksys
)=MKSYS_ITEMMONIKER
;
769 /*******************************************************************************
770 * ItemMonikerIROTData_QueryInterface
771 *******************************************************************************/
772 static HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,
776 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
778 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
780 return ItemMonikerImpl_QueryInterface(&This
->IMoniker_iface
, riid
, ppvObject
);
783 /***********************************************************************
784 * ItemMonikerIROTData_AddRef
786 static ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
*iface
)
788 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
790 TRACE("(%p)\n",iface
);
792 return ItemMonikerImpl_AddRef(&This
->IMoniker_iface
);
795 /***********************************************************************
796 * ItemMonikerIROTData_Release
798 static ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
)
800 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
802 TRACE("(%p)\n",iface
);
804 return ItemMonikerImpl_Release(&This
->IMoniker_iface
);
807 /******************************************************************************
808 * ItemMonikerIROTData_GetComparisonData
809 ******************************************************************************/
810 static HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparisonData(IROTData
* iface
,
815 ItemMonikerImpl
*This
= impl_from_IROTData(iface
);
816 int len
= (strlenW(This
->itemName
)+1);
819 LPWSTR pszItemDelimiter
;
821 TRACE("(%p, %u, %p)\n", pbData
, cbMax
, pcbData
);
823 *pcbData
= sizeof(CLSID
) + sizeof(WCHAR
) + len
* sizeof(WCHAR
);
824 if (cbMax
< *pcbData
)
825 return E_OUTOFMEMORY
;
828 memcpy(pbData
, &CLSID_ItemMoniker
, sizeof(CLSID
));
829 /* write delimiter */
830 pszItemDelimiter
= (LPWSTR
)(pbData
+sizeof(CLSID
));
831 *pszItemDelimiter
= *This
->itemDelimiter
;
833 pszItemName
= pszItemDelimiter
+ 1;
834 for (i
= 0; i
< len
; i
++)
835 pszItemName
[i
] = toupperW(This
->itemName
[i
]);
840 /********************************************************************************/
841 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
842 /* IPersistStream and IMoniker functions. */
843 static const IMonikerVtbl VT_ItemMonikerImpl
=
845 ItemMonikerImpl_QueryInterface
,
846 ItemMonikerImpl_AddRef
,
847 ItemMonikerImpl_Release
,
848 ItemMonikerImpl_GetClassID
,
849 ItemMonikerImpl_IsDirty
,
850 ItemMonikerImpl_Load
,
851 ItemMonikerImpl_Save
,
852 ItemMonikerImpl_GetSizeMax
,
853 ItemMonikerImpl_BindToObject
,
854 ItemMonikerImpl_BindToStorage
,
855 ItemMonikerImpl_Reduce
,
856 ItemMonikerImpl_ComposeWith
,
857 ItemMonikerImpl_Enum
,
858 ItemMonikerImpl_IsEqual
,
859 ItemMonikerImpl_Hash
,
860 ItemMonikerImpl_IsRunning
,
861 ItemMonikerImpl_GetTimeOfLastChange
,
862 ItemMonikerImpl_Inverse
,
863 ItemMonikerImpl_CommonPrefixWith
,
864 ItemMonikerImpl_RelativePathTo
,
865 ItemMonikerImpl_GetDisplayName
,
866 ItemMonikerImpl_ParseDisplayName
,
867 ItemMonikerImpl_IsSystemMoniker
870 /********************************************************************************/
871 /* Virtual function table for the IROTData class. */
872 static const IROTDataVtbl VT_ROTDataImpl
=
874 ItemMonikerROTDataImpl_QueryInterface
,
875 ItemMonikerROTDataImpl_AddRef
,
876 ItemMonikerROTDataImpl_Release
,
877 ItemMonikerROTDataImpl_GetComparisonData
880 /******************************************************************************
881 * ItemMoniker_Construct (local function)
882 *******************************************************************************/
883 static HRESULT
ItemMonikerImpl_Construct(ItemMonikerImpl
* This
, LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
)
886 int sizeStr1
=lstrlenW(lpszItem
), sizeStr2
;
887 static const OLECHAR emptystr
[1];
890 TRACE("(%p,%s,%s)\n",This
,debugstr_w(lpszDelim
),debugstr_w(lpszItem
));
892 /* Initialize the virtual function table. */
893 This
->IMoniker_iface
.lpVtbl
= &VT_ItemMonikerImpl
;
894 This
->IROTData_iface
.lpVtbl
= &VT_ROTDataImpl
;
896 This
->pMarshal
= NULL
;
898 This
->itemName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr1
+1));
900 return E_OUTOFMEMORY
;
901 lstrcpyW(This
->itemName
,lpszItem
);
904 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
906 delim
= lpszDelim
? lpszDelim
: emptystr
;
908 sizeStr2
=lstrlenW(delim
);
909 This
->itemDelimiter
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr2
+1));
910 if (!This
->itemDelimiter
) {
911 HeapFree(GetProcessHeap(),0,This
->itemName
);
912 return E_OUTOFMEMORY
;
914 lstrcpyW(This
->itemDelimiter
,delim
);
918 /******************************************************************************
919 * ItemMoniker_Destroy (local function)
920 *******************************************************************************/
921 static HRESULT
ItemMonikerImpl_Destroy(ItemMonikerImpl
* This
)
923 TRACE("(%p)\n",This
);
925 if (This
->pMarshal
) IUnknown_Release(This
->pMarshal
);
926 HeapFree(GetProcessHeap(),0,This
->itemName
);
927 HeapFree(GetProcessHeap(),0,This
->itemDelimiter
);
928 HeapFree(GetProcessHeap(),0,This
);
933 /******************************************************************************
934 * CreateItemMoniker [OLE32.@]
935 ******************************************************************************/
936 HRESULT WINAPI
CreateItemMoniker(LPCOLESTR lpszDelim
, LPCOLESTR lpszItem
, IMoniker
**ppmk
)
938 ItemMonikerImpl
* newItemMoniker
;
941 TRACE("(%s,%s,%p)\n",debugstr_w(lpszDelim
),debugstr_w(lpszItem
),ppmk
);
943 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
946 return STG_E_INSUFFICIENTMEMORY
;
948 hr
= ItemMonikerImpl_Construct(newItemMoniker
,lpszDelim
,lpszItem
);
952 HeapFree(GetProcessHeap(),0,newItemMoniker
);
956 return ItemMonikerImpl_QueryInterface(&newItemMoniker
->IMoniker_iface
,&IID_IMoniker
,
960 static HRESULT WINAPI
ItemMonikerCF_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
963 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
))
966 IClassFactory_AddRef(iface
);
969 return E_NOINTERFACE
;
972 static ULONG WINAPI
ItemMonikerCF_AddRef(LPCLASSFACTORY iface
)
974 return 2; /* non-heap based object */
977 static ULONG WINAPI
ItemMonikerCF_Release(LPCLASSFACTORY iface
)
979 return 1; /* non-heap based object */
982 static HRESULT WINAPI
ItemMonikerCF_CreateInstance(LPCLASSFACTORY iface
,
983 LPUNKNOWN pUnk
, REFIID riid
, LPVOID
*ppv
)
985 ItemMonikerImpl
* newItemMoniker
;
987 static const WCHAR wszEmpty
[] = { 0 };
989 TRACE("(%p, %s, %p)\n", pUnk
, debugstr_guid(riid
), ppv
);
994 return CLASS_E_NOAGGREGATION
;
996 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
998 return E_OUTOFMEMORY
;
1000 hr
= ItemMonikerImpl_Construct(newItemMoniker
, wszEmpty
, wszEmpty
);
1003 hr
= ItemMonikerImpl_QueryInterface(&newItemMoniker
->IMoniker_iface
, riid
, ppv
);
1005 HeapFree(GetProcessHeap(),0,newItemMoniker
);
1010 static HRESULT WINAPI
ItemMonikerCF_LockServer(LPCLASSFACTORY iface
, BOOL fLock
)
1012 FIXME("(%d), stub!\n",fLock
);
1016 static const IClassFactoryVtbl ItemMonikerCFVtbl
=
1018 ItemMonikerCF_QueryInterface
,
1019 ItemMonikerCF_AddRef
,
1020 ItemMonikerCF_Release
,
1021 ItemMonikerCF_CreateInstance
,
1022 ItemMonikerCF_LockServer
1024 static const IClassFactoryVtbl
*ItemMonikerCF
= &ItemMonikerCFVtbl
;
1026 HRESULT
ItemMonikerCF_Create(REFIID riid
, LPVOID
*ppv
)
1028 return IClassFactory_QueryInterface((IClassFactory
*)&ItemMonikerCF
, riid
, ppv
);