2 * CompositeMonikers implementation
4 * Copyright 1999 Noomen Hamza
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ole);
40 #define BLOCK_TAB_SIZE 5 /* represent the first size table and it's increment block size */
42 /* CompositeMoniker data structure */
43 typedef struct CompositeMonikerImpl{
45 const IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/
47 /* The ROT (RunningObjectTable implementation) uses the IROTData
48 * interface to test whether two monikers are equal. That's why IROTData
49 * interface is implemented by monikers.
51 const IROTDataVtbl* lpvtbl2; /* VTable relative to the IROTData interface.*/
53 const IMarshalVtbl* lpvtblMarshal; /* VTable relative to the IMarshal interface.*/
55 LONG ref; /* reference counter for this object */
57 IMoniker** tabMoniker; /* dynamaic table containing all components (monikers) of this composite moniker */
59 ULONG tabSize; /* size of tabMoniker */
61 ULONG tabLastIndex; /* first free index in tabMoniker */
63 } CompositeMonikerImpl;
66 /* EnumMoniker data structure */
67 typedef struct EnumMonikerImpl{
69 const IEnumMonikerVtbl *lpVtbl; /* VTable relative to the IEnumMoniker interface.*/
71 LONG ref; /* reference counter for this object */
73 IMoniker** tabMoniker; /* dynamic table containing the enumerated monikers */
75 ULONG tabSize; /* size of tabMoniker */
77 ULONG currentPos; /* index pointer on the current moniker */
81 static inline IMoniker *impl_from_IROTData( IROTData *iface )
83 return (IMoniker *)((char*)iface - FIELD_OFFSET(CompositeMonikerImpl, lpvtbl2));
86 static inline IMoniker *impl_from_IMarshal( IMarshal *iface )
88 return (IMoniker *)((char*)iface - FIELD_OFFSET(CompositeMonikerImpl, lpvtblMarshal));
91 static HRESULT EnumMonikerImpl_CreateEnumMoniker(IMoniker** tabMoniker,ULONG tabSize,ULONG currentPos,BOOL leftToRigth,IEnumMoniker ** ppmk);
93 /*******************************************************************************
94 * CompositeMoniker_QueryInterface
95 *******************************************************************************/
97 CompositeMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
99 CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
101 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
103 /* Perform a sanity check on the parameters.*/
104 if ( (This==0) || (ppvObject==0) )
107 /* Initialize the return parameter */
110 /* Compare the riid with the interface IDs implemented by this object.*/
111 if (IsEqualIID(&IID_IUnknown, riid) ||
112 IsEqualIID(&IID_IPersist, riid) ||
113 IsEqualIID(&IID_IPersistStream, riid) ||
114 IsEqualIID(&IID_IMoniker, riid)
117 else if (IsEqualIID(&IID_IROTData, riid))
118 *ppvObject = (IROTData*)&(This->lpvtbl2);
119 else if (IsEqualIID(&IID_IMarshal, riid))
120 *ppvObject = (IROTData*)&(This->lpvtblMarshal);
122 /* Check that we obtained an interface.*/
124 return E_NOINTERFACE;
126 /* Query Interface always increases the reference count by one when it is successful */
127 IMoniker_AddRef(iface);
132 /******************************************************************************
133 * CompositeMoniker_AddRef
134 ******************************************************************************/
136 CompositeMonikerImpl_AddRef(IMoniker* iface)
138 CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
140 TRACE("(%p)\n",This);
142 return InterlockedIncrement(&This->ref);
145 static void CompositeMonikerImpl_ReleaseMonikersInTable(CompositeMonikerImpl *This)
149 for (i = 0; i < This->tabLastIndex; i++)
150 IMoniker_Release(This->tabMoniker[i]);
152 This->tabLastIndex = 0;
155 /******************************************************************************
156 * CompositeMoniker_Release
157 ******************************************************************************/
159 CompositeMonikerImpl_Release(IMoniker* iface)
161 CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
164 TRACE("(%p)\n",This);
166 ref = InterlockedDecrement(&This->ref);
168 /* destroy the object if there's no more reference on it */
171 /* release all the components before destroying this object */
172 CompositeMonikerImpl_ReleaseMonikersInTable(This);
174 HeapFree(GetProcessHeap(),0,This->tabMoniker);
175 HeapFree(GetProcessHeap(),0,This);
180 /******************************************************************************
181 * CompositeMoniker_GetClassID
182 ******************************************************************************/
183 static HRESULT WINAPI
184 CompositeMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
186 TRACE("(%p,%p)\n",iface,pClassID);
191 *pClassID = CLSID_CompositeMoniker;
196 /******************************************************************************
197 * CompositeMoniker_IsDirty
198 ******************************************************************************/
199 static HRESULT WINAPI
200 CompositeMonikerImpl_IsDirty(IMoniker* iface)
202 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
203 method in the OLE-provided moniker interfaces always return S_FALSE because
204 their internal state never changes. */
206 TRACE("(%p)\n",iface);
211 /******************************************************************************
212 * CompositeMoniker_Load
213 ******************************************************************************/
214 static HRESULT WINAPI
215 CompositeMonikerImpl_Load(IMoniker* iface,IStream* pStm)
221 CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
223 TRACE("(%p,%p)\n",iface,pStm);
225 /* this function call OleLoadFromStream function for each moniker within this object */
227 res=IStream_Read(pStm,&moniker_count,sizeof(DWORD),NULL);
230 ERR("couldn't reading moniker count from stream\n");
234 CompositeMonikerImpl_ReleaseMonikersInTable(This);
236 for (i = 0; i < moniker_count; i++)
238 res=OleLoadFromStream(pStm,&IID_IMoniker,(void**)&This->tabMoniker[This->tabLastIndex]);
241 ERR("couldn't load moniker from stream, res = 0x%08x\n", res);
245 /* resize the table if needed */
246 if (++This->tabLastIndex==This->tabSize){
248 This->tabSize+=BLOCK_TAB_SIZE;
249 This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker));
251 if (This->tabMoniker==NULL)
252 return E_OUTOFMEMORY;
259 /******************************************************************************
260 * CompositeMoniker_Save
261 ******************************************************************************/
262 static HRESULT WINAPI
263 CompositeMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
265 CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
267 IEnumMoniker *enumMk;
269 DWORD moniker_count = This->tabLastIndex;
271 TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty);
273 /* This function calls OleSaveToStream function for each moniker within
275 * When I tested this function in windows, I usually found this constant
276 * at the beginning of the stream. I don't known why (there's no
277 * indication in the specification) !
279 res=IStream_Write(pStm,&moniker_count,sizeof(moniker_count),NULL);
280 if (FAILED(res)) return res;
282 IMoniker_Enum(iface,TRUE,&enumMk);
284 while(IEnumMoniker_Next(enumMk,1,&pmk,NULL)==S_OK){
286 res=OleSaveToStream((IPersistStream*)pmk,pStm);
288 IMoniker_Release(pmk);
292 IEnumMoniker_Release(enumMk);
297 IEnumMoniker_Release(enumMk);
302 /******************************************************************************
303 * CompositeMoniker_GetSizeMax
304 ******************************************************************************/
305 static HRESULT WINAPI
306 CompositeMonikerImpl_GetSizeMax(IMoniker* iface,ULARGE_INTEGER* pcbSize)
308 IEnumMoniker *enumMk;
310 ULARGE_INTEGER ptmpSize;
312 /* The sizeMax of this object is calculated by calling GetSizeMax on
313 * each moniker within this object then summing all returned values
316 TRACE("(%p,%p)\n",iface,pcbSize);
321 pcbSize->QuadPart = sizeof(DWORD);
323 IMoniker_Enum(iface,TRUE,&enumMk);
325 while(IEnumMoniker_Next(enumMk,1,&pmk,NULL)==S_OK){
327 IMoniker_GetSizeMax(pmk,&ptmpSize);
329 IMoniker_Release(pmk);
331 pcbSize->QuadPart = ptmpSize.QuadPart + sizeof(CLSID);
334 IEnumMoniker_Release(enumMk);
339 /******************************************************************************
340 * CompositeMoniker_BindToObject
341 ******************************************************************************/
342 static HRESULT WINAPI
343 CompositeMonikerImpl_BindToObject(IMoniker* iface, IBindCtx* pbc,
344 IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult)
347 IRunningObjectTable *prot;
348 IMoniker *tempMk,*antiMk,*mostRigthMk;
349 IEnumMoniker *enumMoniker;
351 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
357 /* If pmkToLeft is NULL, this method looks for the moniker in the ROT, and if found, queries the retrieved */
358 /* object for the requested interface pointer. */
361 res=IBindCtx_GetRunningObjectTable(pbc,&prot);
365 /* if the requested class was loaded before ! we don't need to reload it */
366 res = IRunningObjectTable_GetObject(prot,iface,(IUnknown**)ppvResult);
373 /* If pmkToLeft is not NULL, the method recursively calls IMoniker::BindToObject on the rightmost */
374 /* component of the composite, passing the rest of the composite as the pmkToLeft parameter for that call */
376 IMoniker_Enum(iface,FALSE,&enumMoniker);
377 IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
378 IEnumMoniker_Release(enumMoniker);
380 res=CreateAntiMoniker(&antiMk);
381 res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
382 IMoniker_Release(antiMk);
384 res=IMoniker_BindToObject(mostRigthMk,pbc,tempMk,riid,ppvResult);
386 IMoniker_Release(tempMk);
387 IMoniker_Release(mostRigthMk);
393 /******************************************************************************
394 * CompositeMoniker_BindToStorage
395 ******************************************************************************/
396 static HRESULT WINAPI
397 CompositeMonikerImpl_BindToStorage(IMoniker* iface, IBindCtx* pbc,
398 IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult)
401 IMoniker *tempMk,*antiMk,*mostRigthMk,*leftMk;
402 IEnumMoniker *enumMoniker;
404 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
408 /* This method recursively calls BindToStorage on the rightmost component of the composite, */
409 /* passing the rest of the composite as the pmkToLeft parameter for that call. */
413 res = IMoniker_ComposeWith(pmkToLeft, iface, FALSE, &leftMk);
414 if (FAILED(res)) return res;
419 IMoniker_Enum(iface, FALSE, &enumMoniker);
420 IEnumMoniker_Next(enumMoniker, 1, &mostRigthMk, NULL);
421 IEnumMoniker_Release(enumMoniker);
423 res = CreateAntiMoniker(&antiMk);
424 if (FAILED(res)) return res;
425 res = IMoniker_ComposeWith(leftMk, antiMk, 0, &tempMk);
426 if (FAILED(res)) return res;
427 IMoniker_Release(antiMk);
429 res = IMoniker_BindToStorage(mostRigthMk, pbc, tempMk, riid, ppvResult);
431 IMoniker_Release(tempMk);
433 IMoniker_Release(mostRigthMk);
436 IMoniker_Release(leftMk);
441 /******************************************************************************
442 * CompositeMoniker_Reduce
443 ******************************************************************************/
444 static HRESULT WINAPI
445 CompositeMonikerImpl_Reduce(IMoniker* iface, IBindCtx* pbc, DWORD dwReduceHowFar,
446 IMoniker** ppmkToLeft, IMoniker** ppmkReduced)
449 IMoniker *tempMk,*antiMk,*mostRigthMk,*leftReducedComposedMk,*mostRigthReducedMk;
450 IEnumMoniker *enumMoniker;
452 TRACE("(%p,%p,%d,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
454 if (ppmkReduced==NULL)
457 /* This method recursively calls Reduce for each of its component monikers. */
459 if (ppmkToLeft==NULL){
461 IMoniker_Enum(iface,FALSE,&enumMoniker);
462 IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
463 IEnumMoniker_Release(enumMoniker);
465 res=CreateAntiMoniker(&antiMk);
466 res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
467 IMoniker_Release(antiMk);
469 return IMoniker_Reduce(mostRigthMk,pbc,dwReduceHowFar,&tempMk, ppmkReduced);
471 else if (*ppmkToLeft==NULL)
473 return IMoniker_Reduce(iface,pbc,dwReduceHowFar,NULL,ppmkReduced);
477 /* separate the composite moniker in to left and right moniker */
478 IMoniker_Enum(iface,FALSE,&enumMoniker);
479 IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
480 IEnumMoniker_Release(enumMoniker);
482 res=CreateAntiMoniker(&antiMk);
483 res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
484 IMoniker_Release(antiMk);
486 /* If any of the components reduces itself, the method returns S_OK and passes back a composite */
487 /* of the reduced components */
488 if (IMoniker_Reduce(mostRigthMk,pbc,dwReduceHowFar,NULL,&mostRigthReducedMk) &&
489 IMoniker_Reduce(mostRigthMk,pbc,dwReduceHowFar,&tempMk,&leftReducedComposedMk)
492 return CreateGenericComposite(leftReducedComposedMk,mostRigthReducedMk,ppmkReduced);
495 /* If no reduction occurred, the method passes back the same moniker and returns MK_S_REDUCED_TO_SELF.*/
497 IMoniker_AddRef(iface);
501 return MK_S_REDUCED_TO_SELF;
506 /******************************************************************************
507 * CompositeMoniker_ComposeWith
508 ******************************************************************************/
509 static HRESULT WINAPI
510 CompositeMonikerImpl_ComposeWith(IMoniker* iface, IMoniker* pmkRight,
511 BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite)
513 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
515 if ((ppmkComposite==NULL)||(pmkRight==NULL))
520 /* If fOnlyIfNotGeneric is TRUE, this method sets *pmkComposite to NULL and returns MK_E_NEEDGENERIC; */
521 /* otherwise, the method returns the result of combining the two monikers by calling the */
522 /* CreateGenericComposite function */
524 if (fOnlyIfNotGeneric)
525 return MK_E_NEEDGENERIC;
527 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
530 /******************************************************************************
531 * CompositeMoniker_Enum
532 ******************************************************************************/
533 static HRESULT WINAPI
534 CompositeMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
536 CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
538 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
540 if (ppenumMoniker == NULL)
543 return EnumMonikerImpl_CreateEnumMoniker(This->tabMoniker,This->tabLastIndex,0,fForward,ppenumMoniker);
546 /******************************************************************************
547 * CompositeMoniker_IsEqual
548 ******************************************************************************/
549 static HRESULT WINAPI
550 CompositeMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
552 IEnumMoniker *enumMoniker1,*enumMoniker2;
553 IMoniker *tempMk1,*tempMk2;
554 HRESULT res1,res2,res;
556 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
558 if (pmkOtherMoniker==NULL)
561 /* This method returns S_OK if the components of both monikers are equal when compared in the */
562 /* left-to-right order.*/
563 IMoniker_Enum(pmkOtherMoniker,TRUE,&enumMoniker1);
565 if (enumMoniker1==NULL)
568 IMoniker_Enum(iface,TRUE,&enumMoniker2);
572 res1=IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);
573 res2=IEnumMoniker_Next(enumMoniker2,1,&tempMk2,NULL);
575 if((res1==S_OK)&&(res2==S_OK)){
577 if(IMoniker_IsEqual(tempMk1,tempMk2)==S_FALSE){
584 else if ( (res1==S_FALSE) && (res2==S_FALSE) ){
594 IMoniker_Release(tempMk1);
597 IMoniker_Release(tempMk2);
600 IEnumMoniker_Release(enumMoniker1);
601 IEnumMoniker_Release(enumMoniker2);
605 /******************************************************************************
606 * CompositeMoniker_Hash
607 ******************************************************************************/
608 static HRESULT WINAPI
609 CompositeMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
611 IEnumMoniker *enumMoniker;
616 TRACE("(%p,%p)\n",iface,pdwHash);
621 res = IMoniker_Enum(iface,TRUE,&enumMoniker);
627 while(IEnumMoniker_Next(enumMoniker,1,&tempMk,NULL)==S_OK){
628 res = IMoniker_Hash(tempMk, &tempHash);
631 *pdwHash = *pdwHash ^ tempHash;
633 IMoniker_Release(tempMk);
636 IEnumMoniker_Release(enumMoniker);
641 /******************************************************************************
642 * CompositeMoniker_IsRunning
643 ******************************************************************************/
644 static HRESULT WINAPI
645 CompositeMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc,
646 IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning)
648 IRunningObjectTable* rot;
650 IMoniker *tempMk,*antiMk,*mostRigthMk;
651 IEnumMoniker *enumMoniker;
653 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
655 /* If pmkToLeft is non-NULL, this method composes pmkToLeft with this moniker and calls IsRunning on the result.*/
656 if (pmkToLeft!=NULL){
658 CreateGenericComposite(pmkToLeft,iface,&tempMk);
660 res = IMoniker_IsRunning(tempMk,pbc,NULL,pmkNewlyRunning);
662 IMoniker_Release(tempMk);
667 /* If pmkToLeft is NULL, this method returns S_OK if pmkNewlyRunning is non-NULL and is equal */
668 /* to this moniker */
670 if (pmkNewlyRunning!=NULL)
672 if (IMoniker_IsEqual(iface,pmkNewlyRunning)==S_OK)
683 /* If pmkToLeft and pmkNewlyRunning are both NULL, this method checks the ROT to see whether */
684 /* the moniker is running. If so, the method returns S_OK; otherwise, it recursively calls */
685 /* IMoniker::IsRunning on the rightmost component of the composite, passing the remainder of */
686 /* the composite as the pmkToLeft parameter for that call. */
688 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
693 res = IRunningObjectTable_IsRunning(rot,iface);
694 IRunningObjectTable_Release(rot);
701 IMoniker_Enum(iface,FALSE,&enumMoniker);
702 IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
703 IEnumMoniker_Release(enumMoniker);
705 res=CreateAntiMoniker(&antiMk);
706 res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
707 IMoniker_Release(antiMk);
709 res=IMoniker_IsRunning(mostRigthMk,pbc,tempMk,pmkNewlyRunning);
711 IMoniker_Release(tempMk);
712 IMoniker_Release(mostRigthMk);
719 /******************************************************************************
720 * CompositeMoniker_GetTimeOfLastChange
721 ******************************************************************************/
722 static HRESULT WINAPI
723 CompositeMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc,
724 IMoniker* pmkToLeft, FILETIME* pCompositeTime)
727 IMoniker *tempMk,*antiMk,*mostRigthMk,*leftMk;
728 IEnumMoniker *enumMoniker;
730 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pCompositeTime);
732 if (pCompositeTime==NULL)
735 /* This method creates a composite of pmkToLeft (if non-NULL) and this moniker and uses the ROT to */
736 /* retrieve the time of last change. If the object is not in the ROT, the method recursively calls */
737 /* IMoniker::GetTimeOfLastChange on the rightmost component of the composite, passing the remainder */
738 /* of the composite as the pmkToLeft parameter for that call. */
741 IRunningObjectTable* rot;
743 res = IMoniker_ComposeWith(pmkToLeft, iface, FALSE, &leftMk);
745 res = IBindCtx_GetRunningObjectTable(pbc,&rot);
748 IMoniker_Release(leftMk);
752 if (IRunningObjectTable_GetTimeOfLastChange(rot,leftMk,pCompositeTime)==S_OK)
754 IMoniker_Release(leftMk);
761 IMoniker_Enum(iface, FALSE, &enumMoniker);
762 IEnumMoniker_Next(enumMoniker, 1, &mostRigthMk, NULL);
763 IEnumMoniker_Release(enumMoniker);
765 res = CreateAntiMoniker(&antiMk);
766 res = IMoniker_ComposeWith(leftMk, antiMk, 0, &tempMk);
767 IMoniker_Release(antiMk);
769 res = IMoniker_GetTimeOfLastChange(mostRigthMk, pbc, tempMk, pCompositeTime);
771 IMoniker_Release(tempMk);
772 IMoniker_Release(mostRigthMk);
775 IMoniker_Release(leftMk);
780 /******************************************************************************
781 * CompositeMoniker_Inverse
782 ******************************************************************************/
783 static HRESULT WINAPI
784 CompositeMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
787 IMoniker *tempMk,*antiMk,*mostRigthMk,*tempInvMk,*mostRigthInvMk;
788 IEnumMoniker *enumMoniker;
790 TRACE("(%p,%p)\n",iface,ppmk);
795 /* This method returns a composite moniker that consists of the inverses of each of the components */
796 /* of the original composite, stored in reverse order */
798 res=CreateAntiMoniker(&antiMk);
799 res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
800 IMoniker_Release(antiMk);
804 return IMoniker_Inverse(iface,ppmk);
808 IMoniker_Enum(iface,FALSE,&enumMoniker);
809 IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
810 IEnumMoniker_Release(enumMoniker);
812 IMoniker_Inverse(mostRigthMk,&mostRigthInvMk);
813 CompositeMonikerImpl_Inverse(tempMk,&tempInvMk);
815 res=CreateGenericComposite(mostRigthInvMk,tempInvMk,ppmk);
817 IMoniker_Release(tempMk);
818 IMoniker_Release(mostRigthMk);
819 IMoniker_Release(tempInvMk);
820 IMoniker_Release(mostRigthInvMk);
826 /******************************************************************************
827 * CompositeMoniker_CommonPrefixWith
828 ******************************************************************************/
829 static HRESULT WINAPI
830 CompositeMonikerImpl_CommonPrefixWith(IMoniker* iface, IMoniker* pmkOther,
831 IMoniker** ppmkPrefix)
835 IMoniker *tempMk1,*tempMk2,*mostLeftMk1,*mostLeftMk2;
836 IEnumMoniker *enumMoniker1,*enumMoniker2;
837 ULONG i,nbCommonMk=0;
839 /* If the other moniker is a composite, this method compares the components of each composite from left */
840 /* to right. The returned common prefix moniker might also be a composite moniker, depending on how many */
841 /* of the leftmost components were common to both monikers. */
843 if (ppmkPrefix==NULL)
849 return MK_E_NOPREFIX;
851 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
853 if((mkSys==MKSYS_GENERICCOMPOSITE)){
855 IMoniker_Enum(iface,TRUE,&enumMoniker1);
856 IMoniker_Enum(pmkOther,TRUE,&enumMoniker2);
860 res1=IEnumMoniker_Next(enumMoniker1,1,&mostLeftMk1,NULL);
861 res2=IEnumMoniker_Next(enumMoniker2,1,&mostLeftMk2,NULL);
863 if ((res1==S_FALSE) && (res2==S_FALSE)){
865 /* If the monikers are equal, the method returns MK_S_US and sets ppmkPrefix to this moniker.*/
867 IMoniker_AddRef(iface);
870 else if ((res1==S_OK) && (res2==S_OK)){
872 if (IMoniker_IsEqual(mostLeftMk1,mostLeftMk2)==S_OK)
880 else if (res1==S_OK){
882 /* If the other moniker is a prefix of this moniker, the method returns MK_S_HIM and sets */
883 /* ppmkPrefix to the other moniker. */
884 *ppmkPrefix=pmkOther;
888 /* If this moniker is a prefix of the other, this method returns MK_S_ME and sets ppmkPrefix */
889 /* to this moniker. */
895 IEnumMoniker_Release(enumMoniker1);
896 IEnumMoniker_Release(enumMoniker2);
898 /* If there is no common prefix, this method returns MK_E_NOPREFIX and sets ppmkPrefix to NULL. */
900 return MK_E_NOPREFIX;
902 IEnumMoniker_Reset(enumMoniker1);
904 IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);
906 /* if we have more than one commun moniker the result will be a composite moniker */
909 /* initialize the common prefix moniker with the composite of two first moniker (from the left)*/
910 IEnumMoniker_Next(enumMoniker1,1,&tempMk2,NULL);
911 CreateGenericComposite(tempMk1,tempMk2,ppmkPrefix);
912 IMoniker_Release(tempMk1);
913 IMoniker_Release(tempMk2);
915 /* compose all common monikers in a composite moniker */
916 for(i=0;i<nbCommonMk;i++){
918 IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);
920 CreateGenericComposite(*ppmkPrefix,tempMk1,&tempMk2);
922 IMoniker_Release(*ppmkPrefix);
924 IMoniker_Release(tempMk1);
931 /* if we have only one commun moniker the result will be a simple moniker which is the most-left one*/
938 /* If the other moniker is not a composite, the method simply compares it to the leftmost component
941 IMoniker_Enum(iface,TRUE,&enumMoniker1);
943 IEnumMoniker_Next(enumMoniker1,1,&mostLeftMk1,NULL);
945 if (IMoniker_IsEqual(pmkOther,mostLeftMk1)==S_OK){
947 *ppmkPrefix=pmkOther;
952 return MK_E_NOPREFIX;
956 /***************************************************************************************************
957 * GetAfterCommonPrefix (local function)
958 * This function returns a moniker that consist of the remainder when the common prefix is removed
959 ***************************************************************************************************/
960 static VOID GetAfterCommonPrefix(IMoniker* pGenMk,IMoniker* commonMk,IMoniker** restMk)
962 IMoniker *tempMk,*tempMk1,*tempMk2;
963 IEnumMoniker *enumMoniker1,*enumMoniker2,*enumMoniker3;
970 /* to create an enumerator for pGenMk with current position pointed on the first element after common */
971 /* prefix: enum the two monikers (left-right) then compare these enumerations (left-right) and stop */
972 /* on the first difference. */
973 IMoniker_Enum(pGenMk,TRUE,&enumMoniker1);
975 IMoniker_IsSystemMoniker(commonMk,&mkSys);
977 if (mkSys==MKSYS_GENERICCOMPOSITE){
979 IMoniker_Enum(commonMk,TRUE,&enumMoniker2);
982 res1=IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);
983 res2=IEnumMoniker_Next(enumMoniker2,1,&tempMk2,NULL);
985 if ((res1==S_FALSE)||(res2==S_FALSE)){
991 IMoniker_Release(tempMk1);
992 IMoniker_Release(tempMk1);
996 IMoniker_Release(tempMk1);
997 IMoniker_Release(tempMk1);
1001 IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);
1002 IMoniker_Release(tempMk1);
1005 /* count the number of elements in the enumerator after the common prefix */
1006 IEnumMoniker_Clone(enumMoniker1,&enumMoniker3);
1008 for(;IEnumMoniker_Next(enumMoniker3,1,&tempMk,NULL)==S_OK;nbRestMk++)
1010 IMoniker_Release(tempMk);
1015 /* create a generic composite moniker with monikers located after the common prefix */
1016 IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);
1025 IEnumMoniker_Next(enumMoniker1,1,&tempMk2,NULL);
1027 CreateGenericComposite(tempMk1,tempMk2,restMk);
1029 IMoniker_Release(tempMk1);
1031 IMoniker_Release(tempMk2);
1033 while(IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL)==S_OK){
1035 CreateGenericComposite(*restMk,tempMk1,&tempMk2);
1037 IMoniker_Release(tempMk1);
1039 IMoniker_Release(*restMk);
1046 /******************************************************************************
1047 * CompositeMoniker_RelativePathTo
1048 ******************************************************************************/
1049 static HRESULT WINAPI
1050 CompositeMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmkOther,
1051 IMoniker** ppmkRelPath)
1054 IMoniker *restOtherMk=0,*restThisMk=0,*invRestThisMk=0,*commonMk=0;
1056 TRACE("(%p,%p,%p)\n",iface,pmkOther,ppmkRelPath);
1058 if (ppmkRelPath==NULL)
1063 /* This method finds the common prefix of the two monikers and creates two monikers that consist */
1064 /* of the remainder when the common prefix is removed. Then it creates the inverse for the remainder */
1065 /* of this moniker and composes the remainder of the other moniker on the right of it. */
1067 /* finds the common prefix of the two monikers */
1068 res=IMoniker_CommonPrefixWith(iface,pmkOther,&commonMk);
1070 /* if there's no common prefix or the two moniker are equal the relative is the other moniker */
1071 if ((res== MK_E_NOPREFIX)||(res==MK_S_US)){
1073 *ppmkRelPath=pmkOther;
1074 IMoniker_AddRef(pmkOther);
1078 GetAfterCommonPrefix(iface,commonMk,&restThisMk);
1079 GetAfterCommonPrefix(pmkOther,commonMk,&restOtherMk);
1081 /* if other is a prefix of this moniker the relative path is the inverse of the remainder path of this */
1082 /* moniker when the common prefix is removed */
1085 IMoniker_Inverse(restThisMk,ppmkRelPath);
1086 IMoniker_Release(restThisMk);
1088 /* if this moniker is a prefix of other moniker the relative path is the remainder path of other moniker */
1089 /* when the common prefix is removed */
1090 else if (res==MK_S_ME){
1092 *ppmkRelPath=restOtherMk;
1093 IMoniker_AddRef(restOtherMk);
1095 /* the relative path is the inverse for the remainder of this moniker and the remainder of the other */
1096 /* moniker on the right of it. */
1097 else if (res==S_OK){
1099 IMoniker_Inverse(restThisMk,&invRestThisMk);
1100 IMoniker_Release(restThisMk);
1101 CreateGenericComposite(invRestThisMk,restOtherMk,ppmkRelPath);
1102 IMoniker_Release(invRestThisMk);
1103 IMoniker_Release(restOtherMk);
1108 /******************************************************************************
1109 * CompositeMoniker_GetDisplayName
1110 ******************************************************************************/
1111 static HRESULT WINAPI
1112 CompositeMonikerImpl_GetDisplayName(IMoniker* iface, IBindCtx* pbc,
1113 IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName)
1116 IEnumMoniker *enumMoniker;
1120 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
1122 if (ppszDisplayName==NULL)
1125 *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR));
1127 if (*ppszDisplayName==NULL)
1128 return E_OUTOFMEMORY;
1130 /* This method returns the concatenation of the display names returned by each component moniker of */
1133 **ppszDisplayName=0;
1135 IMoniker_Enum(iface,TRUE,&enumMoniker);
1137 while(IEnumMoniker_Next(enumMoniker,1,&tempMk,NULL)==S_OK){
1139 IMoniker_GetDisplayName(tempMk,pbc,NULL,&tempStr);
1141 lengthStr+=lstrlenW(tempStr);
1143 *ppszDisplayName=CoTaskMemRealloc(*ppszDisplayName,lengthStr * sizeof(WCHAR));
1145 if (*ppszDisplayName==NULL)
1146 return E_OUTOFMEMORY;
1148 strcatW(*ppszDisplayName,tempStr);
1150 CoTaskMemFree(tempStr);
1151 IMoniker_Release(tempMk);
1154 IEnumMoniker_Release(enumMoniker);
1159 /******************************************************************************
1160 * CompositeMoniker_ParseDisplayName
1161 ******************************************************************************/
1162 static HRESULT WINAPI
1163 CompositeMonikerImpl_ParseDisplayName(IMoniker* iface, IBindCtx* pbc,
1164 IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten,
1167 IEnumMoniker *enumMoniker;
1168 IMoniker *tempMk,*mostRigthMk,*antiMk;
1169 /* This method recursively calls IMoniker::ParseDisplayName on the rightmost component of the composite,*/
1170 /* passing everything else as the pmkToLeft parameter for that call. */
1172 /* get the most right moniker */
1173 IMoniker_Enum(iface,FALSE,&enumMoniker);
1174 IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
1175 IEnumMoniker_Release(enumMoniker);
1177 /* get the left moniker */
1178 CreateAntiMoniker(&antiMk);
1179 IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
1180 IMoniker_Release(antiMk);
1182 return IMoniker_ParseDisplayName(mostRigthMk,pbc,tempMk,pszDisplayName,pchEaten,ppmkOut);
1185 /******************************************************************************
1186 * CompositeMoniker_IsSystemMoniker
1187 ******************************************************************************/
1188 static HRESULT WINAPI
1189 CompositeMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
1191 TRACE("(%p,%p)\n",iface,pwdMksys);
1196 (*pwdMksys)=MKSYS_GENERICCOMPOSITE;
1201 /*******************************************************************************
1202 * CompositeMonikerIROTData_QueryInterface
1203 *******************************************************************************/
1204 static HRESULT WINAPI
1205 CompositeMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,
1209 IMoniker *This = impl_from_IROTData(iface);
1211 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
1213 return CompositeMonikerImpl_QueryInterface(This, riid, ppvObject);
1216 /***********************************************************************
1217 * CompositeMonikerIROTData_AddRef
1220 CompositeMonikerROTDataImpl_AddRef(IROTData *iface)
1222 IMoniker *This = impl_from_IROTData(iface);
1224 TRACE("(%p)\n",iface);
1226 return IMoniker_AddRef(This);
1229 /***********************************************************************
1230 * CompositeMonikerIROTData_Release
1232 static ULONG WINAPI CompositeMonikerROTDataImpl_Release(IROTData* iface)
1234 IMoniker *This = impl_from_IROTData(iface);
1236 TRACE("(%p)\n",iface);
1238 return IMoniker_Release(This);
1241 /******************************************************************************
1242 * CompositeMonikerIROTData_GetComparisonData
1243 ******************************************************************************/
1244 static HRESULT WINAPI
1245 CompositeMonikerROTDataImpl_GetComparisonData(IROTData* iface,
1246 BYTE* pbData, ULONG cbMax, ULONG* pcbData)
1248 IMoniker *This = impl_from_IROTData(iface);
1249 IEnumMoniker *pEnumMk;
1253 TRACE("(%p, %u, %p)\n", pbData, cbMax, pcbData);
1255 *pcbData = sizeof(CLSID);
1257 hr = IMoniker_Enum(This, TRUE, &pEnumMk);
1258 if (FAILED(hr)) return hr;
1260 while(IEnumMoniker_Next(pEnumMk, 1, &pmk, NULL) == S_OK)
1263 hr = IMoniker_QueryInterface(pmk, &IID_IROTData, (void **)&pROTData);
1265 ERR("moniker doesn't support IROTData interface\n");
1270 hr = IROTData_GetComparisonData(pROTData, NULL, 0, &cbData);
1271 IROTData_Release(pROTData);
1272 if (SUCCEEDED(hr) || (hr == E_OUTOFMEMORY))
1278 ERR("IROTData_GetComparisonData failed with error 0x%08x\n", hr);
1281 IMoniker_Release(pmk);
1285 IEnumMoniker_Release(pEnumMk);
1289 if (cbMax < *pcbData)
1290 return E_OUTOFMEMORY;
1292 IEnumMoniker_Reset(pEnumMk);
1294 memcpy(pbData, &CLSID_CompositeMoniker, sizeof(CLSID));
1295 pbData += sizeof(CLSID);
1296 cbMax -= sizeof(CLSID);
1298 while (IEnumMoniker_Next(pEnumMk, 1, &pmk, NULL) == S_OK)
1301 hr = IMoniker_QueryInterface(pmk, &IID_IROTData, (void **)&pROTData);
1303 ERR("moniker doesn't support IROTData interface\n");
1308 hr = IROTData_GetComparisonData(pROTData, pbData, cbMax, &cbData);
1309 IROTData_Release(pROTData);
1316 ERR("IROTData_GetComparisonData failed with error 0x%08x\n", hr);
1319 IMoniker_Release(pmk);
1323 IEnumMoniker_Release(pEnumMk);
1328 IEnumMoniker_Release(pEnumMk);
1333 static HRESULT WINAPI CompositeMonikerMarshalImpl_QueryInterface(IMarshal *iface, REFIID riid, LPVOID *ppv)
1335 IMoniker *This = impl_from_IMarshal(iface);
1337 TRACE("(%p,%s,%p)\n",iface,debugstr_guid(riid),ppv);
1339 return CompositeMonikerImpl_QueryInterface(This, riid, ppv);
1342 static ULONG WINAPI CompositeMonikerMarshalImpl_AddRef(IMarshal *iface)
1344 IMoniker *This = impl_from_IMarshal(iface);
1346 TRACE("(%p)\n",iface);
1348 return CompositeMonikerImpl_AddRef(This);
1351 static ULONG WINAPI CompositeMonikerMarshalImpl_Release(IMarshal *iface)
1353 IMoniker *This = impl_from_IMarshal(iface);
1355 TRACE("(%p)\n",iface);
1357 return CompositeMonikerImpl_Release(This);
1360 static HRESULT WINAPI CompositeMonikerMarshalImpl_GetUnmarshalClass(
1361 LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
1362 void* pvDestContext, DWORD mshlflags, CLSID* pCid)
1364 IMoniker *This = impl_from_IMarshal(iface);
1366 TRACE("(%s, %p, %x, %p, %x, %p)\n", debugstr_guid(riid), pv,
1367 dwDestContext, pvDestContext, mshlflags, pCid);
1369 return IMoniker_GetClassID(This, pCid);
1372 static HRESULT WINAPI CompositeMonikerMarshalImpl_GetMarshalSizeMax(
1373 LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
1374 void* pvDestContext, DWORD mshlflags, DWORD* pSize)
1376 IMoniker *This = impl_from_IMarshal(iface);
1377 IEnumMoniker *pEnumMk;
1380 ULARGE_INTEGER size;
1382 TRACE("(%s, %p, %x, %p, %x, %p)\n", debugstr_guid(riid), pv,
1383 dwDestContext, pvDestContext, mshlflags, pSize);
1385 *pSize = 0x10; /* to match native */
1387 hr = IMoniker_Enum(This, TRUE, &pEnumMk);
1388 if (FAILED(hr)) return hr;
1390 hr = IMoniker_GetSizeMax(This, &size);
1392 while (IEnumMoniker_Next(pEnumMk, 1, &pmk, NULL) == S_OK)
1396 hr = CoGetMarshalSizeMax(&size, &IID_IMoniker, (IUnknown *)pmk, dwDestContext, pvDestContext, mshlflags);
1400 IMoniker_Release(pmk);
1404 IEnumMoniker_Release(pEnumMk);
1409 IEnumMoniker_Release(pEnumMk);
1414 static HRESULT WINAPI CompositeMonikerMarshalImpl_MarshalInterface(LPMARSHAL iface, IStream *pStm,
1415 REFIID riid, void* pv, DWORD dwDestContext,
1416 void* pvDestContext, DWORD mshlflags)
1418 IMoniker *This = impl_from_IMarshal(iface);
1419 IEnumMoniker *pEnumMk;
1424 TRACE("(%p, %s, %p, %x, %p, %x)\n", pStm, debugstr_guid(riid), pv,
1425 dwDestContext, pvDestContext, mshlflags);
1427 hr = IMoniker_Enum(This, TRUE, &pEnumMk);
1428 if (FAILED(hr)) return hr;
1430 while (IEnumMoniker_Next(pEnumMk, 1, &pmk, NULL) == S_OK)
1432 hr = CoMarshalInterface(pStm, &IID_IMoniker, (IUnknown *)pmk, dwDestContext, pvDestContext, mshlflags);
1434 IMoniker_Release(pmk);
1438 IEnumMoniker_Release(pEnumMk);
1445 FIXME("moniker count of %d not supported\n", i);
1447 IEnumMoniker_Release(pEnumMk);
1452 static HRESULT WINAPI CompositeMonikerMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv)
1454 CompositeMonikerImpl *This = (CompositeMonikerImpl *)impl_from_IMarshal(iface);
1457 TRACE("(%p, %s, %p)\n", pStm, debugstr_guid(riid), ppv);
1459 CompositeMonikerImpl_ReleaseMonikersInTable(This);
1461 /* resize the table if needed */
1462 if (This->tabLastIndex + 2 > This->tabSize)
1464 This->tabSize += max(BLOCK_TAB_SIZE, 2);
1465 This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker));
1467 if (This->tabMoniker==NULL)
1468 return E_OUTOFMEMORY;
1471 hr = CoUnmarshalInterface(pStm, &IID_IMoniker, (void**)&This->tabMoniker[This->tabLastIndex]);
1474 ERR("couldn't unmarshal moniker, hr = 0x%08x\n", hr);
1477 This->tabLastIndex++;
1478 hr = CoUnmarshalInterface(pStm, &IID_IMoniker, (void**)&This->tabMoniker[This->tabLastIndex]);
1481 ERR("couldn't unmarshal moniker, hr = 0x%08x\n", hr);
1484 This->tabLastIndex++;
1486 return IMoniker_QueryInterface((IMoniker *)&This->lpvtbl1, riid, ppv);
1489 static HRESULT WINAPI CompositeMonikerMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm)
1491 TRACE("(%p)\n", pStm);
1492 /* can't release a state-based marshal as nothing on server side to
1497 static HRESULT WINAPI CompositeMonikerMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwReserved)
1499 TRACE("(0x%x)\n", dwReserved);
1500 /* can't disconnect a state-based marshal as nothing on server side to
1501 * disconnect from */
1505 /******************************************************************************
1506 * EnumMonikerImpl_QueryInterface
1507 ******************************************************************************/
1508 static HRESULT WINAPI
1509 EnumMonikerImpl_QueryInterface(IEnumMoniker* iface,REFIID riid,void** ppvObject)
1511 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
1513 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
1515 /* Perform a sanity check on the parameters.*/
1516 if ( (This==0) || (ppvObject==0) )
1517 return E_INVALIDARG;
1519 /* Initialize the return parameter */
1522 /* Compare the riid with the interface IDs implemented by this object.*/
1523 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumMoniker, riid))
1526 /* Check that we obtained an interface.*/
1527 if ((*ppvObject)==0)
1528 return E_NOINTERFACE;
1530 /* Query Interface always increases the reference count by one when it is successful */
1531 IEnumMoniker_AddRef(iface);
1536 /******************************************************************************
1537 * EnumMonikerImpl_AddRef
1538 ******************************************************************************/
1540 EnumMonikerImpl_AddRef(IEnumMoniker* iface)
1542 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
1544 TRACE("(%p)\n",This);
1546 return InterlockedIncrement(&This->ref);
1550 /******************************************************************************
1551 * EnumMonikerImpl_Release
1552 ******************************************************************************/
1554 EnumMonikerImpl_Release(IEnumMoniker* iface)
1556 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
1559 TRACE("(%p)\n",This);
1561 ref = InterlockedDecrement(&This->ref);
1563 /* destroy the object if there's no more reference on it */
1566 for(i=0;i<This->tabSize;i++)
1567 IMoniker_Release(This->tabMoniker[i]);
1569 HeapFree(GetProcessHeap(),0,This->tabMoniker);
1570 HeapFree(GetProcessHeap(),0,This);
1575 /******************************************************************************
1576 * EnumMonikerImpl_Next
1577 ******************************************************************************/
1578 static HRESULT WINAPI
1579 EnumMonikerImpl_Next(IEnumMoniker* iface,ULONG celt, IMoniker** rgelt,
1582 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
1585 /* retrieve the requested number of moniker from the current position */
1586 for(i=0;((This->currentPos < This->tabSize) && (i < celt));i++)
1588 rgelt[i]=This->tabMoniker[This->currentPos++];
1589 IMoniker_AddRef(rgelt[i]);
1592 if (pceltFethed!=NULL)
1601 /******************************************************************************
1602 * EnumMonikerImpl_Skip
1603 ******************************************************************************/
1604 static HRESULT WINAPI
1605 EnumMonikerImpl_Skip(IEnumMoniker* iface,ULONG celt)
1607 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
1609 if ((This->currentPos+celt) >= This->tabSize)
1612 This->currentPos+=celt;
1617 /******************************************************************************
1618 * EnumMonikerImpl_Reset
1619 ******************************************************************************/
1620 static HRESULT WINAPI
1621 EnumMonikerImpl_Reset(IEnumMoniker* iface)
1624 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
1631 /******************************************************************************
1632 * EnumMonikerImpl_Clone
1633 ******************************************************************************/
1634 static HRESULT WINAPI
1635 EnumMonikerImpl_Clone(IEnumMoniker* iface,IEnumMoniker** ppenum)
1637 EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
1639 return EnumMonikerImpl_CreateEnumMoniker(This->tabMoniker,This->tabSize,This->currentPos,TRUE,ppenum);
1642 /********************************************************************************/
1643 /* Virtual function table for the IROTData class */
1644 static const IEnumMonikerVtbl VT_EnumMonikerImpl =
1646 EnumMonikerImpl_QueryInterface,
1647 EnumMonikerImpl_AddRef,
1648 EnumMonikerImpl_Release,
1649 EnumMonikerImpl_Next,
1650 EnumMonikerImpl_Skip,
1651 EnumMonikerImpl_Reset,
1652 EnumMonikerImpl_Clone
1655 /******************************************************************************
1656 * EnumMonikerImpl_CreateEnumMoniker
1657 ******************************************************************************/
1659 EnumMonikerImpl_CreateEnumMoniker(IMoniker** tabMoniker, ULONG tabSize,
1660 ULONG currentPos, BOOL leftToRigth, IEnumMoniker ** ppmk)
1662 EnumMonikerImpl* newEnumMoniker;
1665 if (currentPos > tabSize)
1666 return E_INVALIDARG;
1668 newEnumMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(EnumMonikerImpl));
1670 if (newEnumMoniker == 0)
1671 return STG_E_INSUFFICIENTMEMORY;
1673 /* Initialize the virtual function table. */
1674 newEnumMoniker->lpVtbl = &VT_EnumMonikerImpl;
1675 newEnumMoniker->ref = 1;
1677 newEnumMoniker->tabSize=tabSize;
1678 newEnumMoniker->currentPos=currentPos;
1680 newEnumMoniker->tabMoniker=HeapAlloc(GetProcessHeap(),0,tabSize*sizeof(IMoniker));
1682 if (newEnumMoniker->tabMoniker==NULL) {
1683 HeapFree(GetProcessHeap(), 0, newEnumMoniker);
1684 return E_OUTOFMEMORY;
1688 for (i=0;i<tabSize;i++){
1690 newEnumMoniker->tabMoniker[i]=tabMoniker[i];
1691 IMoniker_AddRef(tabMoniker[i]);
1694 for (i=tabSize-1;i>=0;i--){
1696 newEnumMoniker->tabMoniker[tabSize-i-1]=tabMoniker[i];
1697 IMoniker_AddRef(tabMoniker[i]);
1700 *ppmk=(IEnumMoniker*)newEnumMoniker;
1705 /********************************************************************************/
1706 /* Virtual function table for the CompositeMonikerImpl class which includes */
1707 /* IPersist, IPersistStream and IMoniker functions. */
1709 static const IMonikerVtbl VT_CompositeMonikerImpl =
1711 CompositeMonikerImpl_QueryInterface,
1712 CompositeMonikerImpl_AddRef,
1713 CompositeMonikerImpl_Release,
1714 CompositeMonikerImpl_GetClassID,
1715 CompositeMonikerImpl_IsDirty,
1716 CompositeMonikerImpl_Load,
1717 CompositeMonikerImpl_Save,
1718 CompositeMonikerImpl_GetSizeMax,
1719 CompositeMonikerImpl_BindToObject,
1720 CompositeMonikerImpl_BindToStorage,
1721 CompositeMonikerImpl_Reduce,
1722 CompositeMonikerImpl_ComposeWith,
1723 CompositeMonikerImpl_Enum,
1724 CompositeMonikerImpl_IsEqual,
1725 CompositeMonikerImpl_Hash,
1726 CompositeMonikerImpl_IsRunning,
1727 CompositeMonikerImpl_GetTimeOfLastChange,
1728 CompositeMonikerImpl_Inverse,
1729 CompositeMonikerImpl_CommonPrefixWith,
1730 CompositeMonikerImpl_RelativePathTo,
1731 CompositeMonikerImpl_GetDisplayName,
1732 CompositeMonikerImpl_ParseDisplayName,
1733 CompositeMonikerImpl_IsSystemMoniker
1736 /********************************************************************************/
1737 /* Virtual function table for the IROTData class. */
1738 static const IROTDataVtbl VT_ROTDataImpl =
1740 CompositeMonikerROTDataImpl_QueryInterface,
1741 CompositeMonikerROTDataImpl_AddRef,
1742 CompositeMonikerROTDataImpl_Release,
1743 CompositeMonikerROTDataImpl_GetComparisonData
1746 static const IMarshalVtbl VT_MarshalImpl =
1748 CompositeMonikerMarshalImpl_QueryInterface,
1749 CompositeMonikerMarshalImpl_AddRef,
1750 CompositeMonikerMarshalImpl_Release,
1751 CompositeMonikerMarshalImpl_GetUnmarshalClass,
1752 CompositeMonikerMarshalImpl_GetMarshalSizeMax,
1753 CompositeMonikerMarshalImpl_MarshalInterface,
1754 CompositeMonikerMarshalImpl_UnmarshalInterface,
1755 CompositeMonikerMarshalImpl_ReleaseMarshalData,
1756 CompositeMonikerMarshalImpl_DisconnectObject
1759 /******************************************************************************
1760 * Composite-Moniker_Construct (local function)
1761 *******************************************************************************/
1763 CompositeMonikerImpl_Construct(IMoniker** ppMoniker,
1764 LPMONIKER pmkFirst, LPMONIKER pmkRest)
1767 IEnumMoniker *enumMoniker;
1770 CompositeMonikerImpl *This;
1772 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1775 return E_OUTOFMEMORY;
1777 TRACE("(%p,%p,%p)\n",This,pmkFirst,pmkRest);
1779 /* Initialize the virtual function table. */
1780 This->lpvtbl1 = &VT_CompositeMonikerImpl;
1781 This->lpvtbl2 = &VT_ROTDataImpl;
1782 This->lpvtblMarshal= &VT_MarshalImpl;
1785 This->tabSize=BLOCK_TAB_SIZE;
1786 This->tabLastIndex=0;
1788 This->tabMoniker=HeapAlloc(GetProcessHeap(),0,This->tabSize*sizeof(IMoniker));
1789 if (This->tabMoniker==NULL) {
1790 HeapFree(GetProcessHeap(), 0, This);
1791 return E_OUTOFMEMORY;
1794 if (!pmkFirst && !pmkRest)
1796 *ppMoniker = (IMoniker *)This;
1800 IMoniker_IsSystemMoniker(pmkFirst,&mkSys);
1802 /* put the first moniker contents in the beginning of the table */
1803 if (mkSys!=MKSYS_GENERICCOMPOSITE){
1805 This->tabMoniker[(This->tabLastIndex)++]=pmkFirst;
1806 IMoniker_AddRef(pmkFirst);
1810 IMoniker_Enum(pmkFirst,TRUE,&enumMoniker);
1812 while(IEnumMoniker_Next(enumMoniker,1,&This->tabMoniker[This->tabLastIndex],NULL)==S_OK){
1815 if (++This->tabLastIndex==This->tabSize){
1816 LPVOID tab_moniker = This->tabMoniker;
1818 This->tabSize+=BLOCK_TAB_SIZE;
1819 This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker));
1821 if (This->tabMoniker==NULL){
1822 HeapFree(GetProcessHeap(), 0, tab_moniker);
1823 HeapFree(GetProcessHeap(), 0, This);
1824 return E_OUTOFMEMORY;
1829 IEnumMoniker_Release(enumMoniker);
1832 /* put the rest moniker contents after the first one and make simplification if needed */
1834 IMoniker_IsSystemMoniker(pmkRest,&mkSys);
1836 if (mkSys!=MKSYS_GENERICCOMPOSITE){
1838 /* add a simple moniker to the moniker table */
1840 res=IMoniker_ComposeWith(This->tabMoniker[This->tabLastIndex-1],pmkRest,TRUE,&tempMk);
1842 if (res==MK_E_NEEDGENERIC){
1844 /* there's no simplification in this case */
1845 This->tabMoniker[This->tabLastIndex]=pmkRest;
1847 This->tabLastIndex++;
1849 IMoniker_AddRef(pmkRest);
1851 else if (tempMk==NULL){
1853 /* we have an antimoniker after a simple moniker so we can make a simplification in this case */
1854 IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]);
1856 This->tabLastIndex--;
1858 else if (SUCCEEDED(res)){
1860 /* the non-generic composition was successful so we can make a simplification in this case */
1861 IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]);
1863 This->tabMoniker[This->tabLastIndex-1]=tempMk;
1867 /* resize tabMoniker if needed */
1868 if (This->tabLastIndex==This->tabSize){
1869 LPVOID tab_moniker = This->tabMoniker;
1871 This->tabSize+=BLOCK_TAB_SIZE;
1873 This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker));
1875 if (This->tabMoniker==NULL){
1876 HeapFree(GetProcessHeap(), 0, tab_moniker);
1877 HeapFree(GetProcessHeap(), 0, This);
1878 return E_OUTOFMEMORY;
1884 /* add a composite moniker to the moniker table (do the same thing
1885 * for each moniker within the composite moniker as a simple moniker
1886 * (see above for how to add a simple moniker case) )
1888 IMoniker_Enum(pmkRest,TRUE,&enumMoniker);
1890 while(IEnumMoniker_Next(enumMoniker,1,&This->tabMoniker[This->tabLastIndex],NULL)==S_OK){
1892 res=IMoniker_ComposeWith(This->tabMoniker[This->tabLastIndex-1],This->tabMoniker[This->tabLastIndex],TRUE,&tempMk);
1894 if (res==MK_E_NEEDGENERIC){
1896 This->tabLastIndex++;
1898 else if (tempMk==NULL){
1900 IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]);
1901 IMoniker_Release(This->tabMoniker[This->tabLastIndex]);
1902 This->tabLastIndex--;
1906 IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]);
1908 This->tabMoniker[This->tabLastIndex-1]=tempMk;
1911 if (This->tabLastIndex==This->tabSize){
1912 LPVOID tab_moniker = This->tabMoniker;
1914 This->tabSize+=BLOCK_TAB_SIZE;
1916 This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker));
1918 if (This->tabMoniker==NULL){
1919 HeapFree(GetProcessHeap(), 0, tab_moniker);
1920 HeapFree(GetProcessHeap(), 0, This);
1921 return E_OUTOFMEMORY;
1926 IEnumMoniker_Release(enumMoniker);
1929 /* only one moniker, then just return it */
1930 if (This->tabLastIndex == 1)
1932 *ppMoniker = This->tabMoniker[0];
1933 IMoniker_AddRef(*ppMoniker);
1934 IMoniker_Release((IMoniker *)This);
1937 *ppMoniker = (IMoniker *)This;
1942 /******************************************************************************
1943 * CreateGenericComposite [OLE32.@]
1944 ******************************************************************************/
1946 CreateGenericComposite(LPMONIKER pmkFirst, LPMONIKER pmkRest,
1947 LPMONIKER* ppmkComposite)
1949 IMoniker* moniker = 0;
1952 TRACE("(%p,%p,%p)\n",pmkFirst,pmkRest,ppmkComposite);
1954 if (ppmkComposite==NULL)
1959 if (pmkFirst==NULL && pmkRest!=NULL){
1961 *ppmkComposite=pmkRest;
1964 else if (pmkFirst!=NULL && pmkRest==NULL){
1965 *ppmkComposite=pmkFirst;
1968 else if (pmkFirst==NULL && pmkRest==NULL)
1971 hr = CompositeMonikerImpl_Construct(&moniker,pmkFirst,pmkRest);
1976 hr = IMoniker_QueryInterface(moniker,&IID_IMoniker,(void**)ppmkComposite);
1977 IMoniker_Release(moniker);
1982 /******************************************************************************
1983 * MonikerCommonPrefixWith [OLE32.@]
1984 ******************************************************************************/
1986 MonikerCommonPrefixWith(IMoniker* pmkThis,IMoniker* pmkOther,IMoniker** ppmkCommon)
1988 FIXME("(),stub!\n");
1992 static HRESULT WINAPI CompositeMonikerCF_QueryInterface(LPCLASSFACTORY iface,
1993 REFIID riid, LPVOID *ppv)
1996 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
1999 IUnknown_AddRef(iface);
2002 return E_NOINTERFACE;
2005 static ULONG WINAPI CompositeMonikerCF_AddRef(LPCLASSFACTORY iface)
2007 return 2; /* non-heap based object */
2010 static ULONG WINAPI CompositeMonikerCF_Release(LPCLASSFACTORY iface)
2012 return 1; /* non-heap based object */
2015 static HRESULT WINAPI CompositeMonikerCF_CreateInstance(LPCLASSFACTORY iface,
2016 LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
2021 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);
2026 return CLASS_E_NOAGGREGATION;
2028 hr = CompositeMonikerImpl_Construct(&pMoniker, NULL, NULL);
2032 hr = IMoniker_QueryInterface(pMoniker, riid, ppv);
2033 IMoniker_Release(pMoniker);
2039 static HRESULT WINAPI CompositeMonikerCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
2041 FIXME("(%d), stub!\n",fLock);
2045 static const IClassFactoryVtbl CompositeMonikerCFVtbl =
2047 CompositeMonikerCF_QueryInterface,
2048 CompositeMonikerCF_AddRef,
2049 CompositeMonikerCF_Release,
2050 CompositeMonikerCF_CreateInstance,
2051 CompositeMonikerCF_LockServer
2053 static const IClassFactoryVtbl *CompositeMonikerCF = &CompositeMonikerCFVtbl;
2055 HRESULT CompositeMonikerCF_Create(REFIID riid, LPVOID *ppv)
2057 return IClassFactory_QueryInterface((IClassFactory *)&CompositeMonikerCF, riid, ppv);