1 /***************************************************************************************
2 * AntiMonikers implementation
4 * Copyright 1999 Noomen Hamza
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ***************************************************************************************/
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
32 #include "wine/unicode.h"
34 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ole);
39 const CLSID CLSID_AntiMoniker = {
40 0x305, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
43 /* AntiMoniker data structure */
44 typedef struct AntiMonikerImpl{
46 IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/
48 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
49 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
51 IROTDataVtbl* lpvtbl2; /* VTable relative to the IROTData interface.*/
53 ULONG ref; /* reference counter for this object */
57 /********************************************************************************/
58 /* AntiMoniker prototype functions : */
60 /* IUnknown prototype functions */
61 static HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
62 static ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface);
63 static ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface);
65 /* IPersist prototype functions */
66 static HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
68 /* IPersistStream prototype functions */
69 static HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface);
70 static HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface, IStream* pStm);
71 static HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
72 static HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
74 /* IMoniker prototype functions */
75 static HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
76 static HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
77 static HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
78 static HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
79 static HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
80 static HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
81 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
82 static HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
83 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pAntiTime);
84 static HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
85 static HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
86 static HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
87 static HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
88 static HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
89 static HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
91 /********************************************************************************/
92 /* IROTData prototype functions */
94 /* IUnknown prototype functions */
95 static HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
96 static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData* iface);
97 static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface);
99 /* IROTData prototype function */
100 static HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
102 /* Local function used by AntiMoniker implementation */
103 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* iface);
104 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* iface);
106 /********************************************************************************/
107 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
108 /* IPersistStream and IMoniker functions. */
109 static IMonikerVtbl VT_AntiMonikerImpl =
111 AntiMonikerImpl_QueryInterface,
112 AntiMonikerImpl_AddRef,
113 AntiMonikerImpl_Release,
114 AntiMonikerImpl_GetClassID,
115 AntiMonikerImpl_IsDirty,
116 AntiMonikerImpl_Load,
117 AntiMonikerImpl_Save,
118 AntiMonikerImpl_GetSizeMax,
119 AntiMonikerImpl_BindToObject,
120 AntiMonikerImpl_BindToStorage,
121 AntiMonikerImpl_Reduce,
122 AntiMonikerImpl_ComposeWith,
123 AntiMonikerImpl_Enum,
124 AntiMonikerImpl_IsEqual,
125 AntiMonikerImpl_Hash,
126 AntiMonikerImpl_IsRunning,
127 AntiMonikerImpl_GetTimeOfLastChange,
128 AntiMonikerImpl_Inverse,
129 AntiMonikerImpl_CommonPrefixWith,
130 AntiMonikerImpl_RelativePathTo,
131 AntiMonikerImpl_GetDisplayName,
132 AntiMonikerImpl_ParseDisplayName,
133 AntiMonikerImpl_IsSystemMoniker
136 /********************************************************************************/
137 /* Virtual function table for the IROTData class. */
138 static IROTDataVtbl VT_ROTDataImpl =
140 AntiMonikerROTDataImpl_QueryInterface,
141 AntiMonikerROTDataImpl_AddRef,
142 AntiMonikerROTDataImpl_Release,
143 AntiMonikerROTDataImpl_GetComparaisonData
146 /*******************************************************************************
147 * AntiMoniker_QueryInterface
148 *******************************************************************************/
149 HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
151 AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
153 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
155 /* Perform a sanity check on the parameters.*/
156 if ( (This==0) || (ppvObject==0) )
159 /* Initialize the return parameter */
162 /* Compare the riid with the interface IDs implemented by this object.*/
163 if (IsEqualIID(&IID_IUnknown, riid) ||
164 IsEqualIID(&IID_IPersist, riid) ||
165 IsEqualIID(&IID_IPersistStream, riid) ||
166 IsEqualIID(&IID_IMoniker, riid)
169 else if (IsEqualIID(&IID_IROTData, riid))
170 *ppvObject = (IROTData*)&(This->lpvtbl2);
172 /* Check that we obtained an interface.*/
174 return E_NOINTERFACE;
176 /* Query Interface always increases the reference count by one when it is successful */
177 AntiMonikerImpl_AddRef(iface);
182 /******************************************************************************
184 ******************************************************************************/
185 ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface)
187 AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
189 TRACE("(%p)\n",This);
191 return InterlockedIncrement(&This->ref);
194 /******************************************************************************
195 * AntiMoniker_Release
196 ******************************************************************************/
197 ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface)
199 AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
202 TRACE("(%p)\n",This);
204 ref = InterlockedDecrement(&This->ref);
206 /* destroy the object if there's no more reference on it */
207 if (ref == 0) AntiMonikerImpl_Destroy(This);
212 /******************************************************************************
213 * AntiMoniker_GetClassID
214 ******************************************************************************/
215 HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
217 TRACE("(%p,%p),stub!\n",iface,pClassID);
222 *pClassID = CLSID_AntiMoniker;
227 /******************************************************************************
228 * AntiMoniker_IsDirty
229 ******************************************************************************/
230 HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface)
232 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
233 method in the OLE-provided moniker interfaces always return S_FALSE because
234 their internal state never changes. */
236 TRACE("(%p)\n",iface);
241 /******************************************************************************
243 ******************************************************************************/
244 HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
246 DWORD constant=1,dwbuffer;
249 /* data read by this function is only a DWORD constant (must be 1) ! */
250 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),NULL);
252 if (SUCCEEDED(res)&& dwbuffer!=constant)
258 /******************************************************************************
260 ******************************************************************************/
261 HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
266 /* data written by this function is only a DWORD constant set to 1 ! */
267 res=IStream_Write(pStm,&constant,sizeof(constant),NULL);
272 /******************************************************************************
273 * AntiMoniker_GetSizeMax
274 ******************************************************************************/
275 HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface,
276 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
278 TRACE("(%p,%p)\n",iface,pcbSize);
283 /* for more details see AntiMonikerImpl_Save coments */
285 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
286 /* more than the number of bytes used by AntiMoniker::Save function */
287 pcbSize->u.LowPart = sizeof(DWORD)+16;
289 pcbSize->u.HighPart=0;
294 /******************************************************************************
295 * AntiMoniker_Construct (local function)
296 *******************************************************************************/
297 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* This)
300 TRACE("(%p)\n",This);
302 /* Initialize the virtual fgunction table. */
303 This->lpvtbl1 = &VT_AntiMonikerImpl;
304 This->lpvtbl2 = &VT_ROTDataImpl;
310 /******************************************************************************
311 * AntiMoniker_Destroy (local function)
312 *******************************************************************************/
313 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* This)
315 TRACE("(%p)\n",This);
317 return HeapFree(GetProcessHeap(),0,This);
320 /******************************************************************************
321 * AntiMoniker_BindToObject
322 ******************************************************************************/
323 HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,
329 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
333 /******************************************************************************
334 * AntiMoniker_BindToStorage
335 ******************************************************************************/
336 HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,
342 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
346 /******************************************************************************
348 ******************************************************************************/
349 HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,
351 DWORD dwReduceHowFar,
352 IMoniker** ppmkToLeft,
353 IMoniker** ppmkReduced)
355 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
357 if (ppmkReduced==NULL)
360 AntiMonikerImpl_AddRef(iface);
364 return MK_S_REDUCED_TO_SELF;
366 /******************************************************************************
367 * AntiMoniker_ComposeWith
368 ******************************************************************************/
369 HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,
371 BOOL fOnlyIfNotGeneric,
372 IMoniker** ppmkComposite)
375 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
377 if ((ppmkComposite==NULL)||(pmkRight==NULL))
382 if (fOnlyIfNotGeneric)
383 return MK_E_NEEDGENERIC;
385 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
388 /******************************************************************************
390 ******************************************************************************/
391 HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
393 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
395 if (ppenumMoniker == NULL)
398 *ppenumMoniker = NULL;
403 /******************************************************************************
404 * AntiMoniker_IsEqual
405 ******************************************************************************/
406 HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
410 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
412 if (pmkOtherMoniker==NULL)
415 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
417 if (mkSys==MKSYS_ANTIMONIKER)
423 /******************************************************************************
425 ******************************************************************************/
426 HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
436 /******************************************************************************
437 * AntiMoniker_IsRunning
438 ******************************************************************************/
439 HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,
442 IMoniker* pmkNewlyRunning)
444 IRunningObjectTable* rot;
447 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
452 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
457 res = IRunningObjectTable_IsRunning(rot,iface);
459 IRunningObjectTable_Release(rot);
464 /******************************************************************************
465 * AntiMoniker_GetTimeOfLastChange
466 ******************************************************************************/
467 HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
472 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
476 /******************************************************************************
477 * AntiMoniker_Inverse
478 ******************************************************************************/
479 HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
481 TRACE("(%p,%p)\n",iface,ppmk);
488 return MK_E_NOINVERSE;
491 /******************************************************************************
492 * AntiMoniker_CommonPrefixWith
493 ******************************************************************************/
494 HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
498 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
500 if(mkSys==MKSYS_ITEMMONIKER){
502 IMoniker_AddRef(iface);
506 IMoniker_AddRef(iface);
511 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
514 /******************************************************************************
515 * AntiMoniker_RelativePathTo
516 ******************************************************************************/
517 HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
519 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
521 if (ppmkRelPath==NULL)
524 IMoniker_AddRef(pmOther);
526 *ppmkRelPath=pmOther;
531 /******************************************************************************
532 * AntiMoniker_GetDisplayName
533 ******************************************************************************/
534 HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,
537 LPOLESTR *ppszDisplayName)
539 static const WCHAR back[]={'\\','.','.',0};
541 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
543 if (ppszDisplayName==NULL)
546 if (pmkToLeft!=NULL){
547 FIXME("() pmkToLeft!=NULL not implemented \n");
551 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
553 if (*ppszDisplayName==NULL)
554 return E_OUTOFMEMORY;
556 strcpyW(*ppszDisplayName,back);
561 /******************************************************************************
562 * AntiMoniker_ParseDisplayName
563 ******************************************************************************/
564 HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,
567 LPOLESTR pszDisplayName,
571 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
575 /******************************************************************************
576 * AntiMoniker_IsSystemMoniker
577 ******************************************************************************/
578 HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
580 TRACE("(%p,%p)\n",iface,pwdMksys);
585 (*pwdMksys)=MKSYS_ANTIMONIKER;
590 /*******************************************************************************
591 * AntiMonikerIROTData_QueryInterface
592 *******************************************************************************/
593 HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
596 ICOM_THIS_From_IROTData(IMoniker, iface);
598 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
600 return AntiMonikerImpl_QueryInterface(This, riid, ppvObject);
603 /***********************************************************************
604 * AntiMonikerIROTData_AddRef
606 ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
608 ICOM_THIS_From_IROTData(IMoniker, iface);
610 TRACE("(%p)\n",iface);
612 return AntiMonikerImpl_AddRef(This);
615 /***********************************************************************
616 * AntiMonikerIROTData_Release
618 ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
620 ICOM_THIS_From_IROTData(IMoniker, iface);
622 TRACE("(%p)\n",iface);
624 return AntiMonikerImpl_Release(This);
627 /******************************************************************************
628 * AntiMonikerIROTData_GetComparaisonData
629 ******************************************************************************/
630 HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
639 /******************************************************************************
640 * CreateAntiMoniker [OLE32.@]
641 ******************************************************************************/
642 HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
644 AntiMonikerImpl* newAntiMoniker = 0;
646 IID riid=IID_IMoniker;
648 TRACE("(%p)\n",ppmk);
650 newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));
652 if (newAntiMoniker == 0)
653 return STG_E_INSUFFICIENTMEMORY;
655 hr = AntiMonikerImpl_Construct(newAntiMoniker);
659 HeapFree(GetProcessHeap(),0,newAntiMoniker);
663 hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk);