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 ***************************************************************************************/
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
30 #include "wine/unicode.h"
32 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(ole);
37 const CLSID CLSID_AntiMoniker = {
38 0x305, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
41 /* AntiMoniker data structure */
42 typedef struct AntiMonikerImpl{
44 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
46 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
47 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
49 ICOM_VTABLE(IROTData)* lpvtbl2; /* VTable relative to the IROTData interface.*/
51 ULONG ref; /* reference counter for this object */
55 /********************************************************************************/
56 /* AntiMoniker prototype functions : */
58 /* IUnknown prototype functions */
59 static HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
60 static ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface);
61 static ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface);
63 /* IPersist prototype functions */
64 static HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
66 /* IPersistStream prototype functions */
67 static HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface);
68 static HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface, IStream* pStm);
69 static HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
70 static HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
72 /* IMoniker prototype functions */
73 static HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
74 static HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
75 static HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
76 static HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
77 static HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
78 static HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
79 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
80 static HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
81 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pAntiTime);
82 static HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
83 static HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
84 static HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
85 static HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
86 static HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
87 static HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
89 /********************************************************************************/
90 /* IROTData prototype functions */
92 /* IUnknown prototype functions */
93 static HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
94 static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData* iface);
95 static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface);
97 /* IROTData prototype function */
98 static HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
100 /* Local function used by AntiMoniker implementation */
101 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* iface);
102 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* iface);
104 /********************************************************************************/
105 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
106 /* IPersistStream and IMoniker functions. */
107 static ICOM_VTABLE(IMoniker) VT_AntiMonikerImpl =
109 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
110 AntiMonikerImpl_QueryInterface,
111 AntiMonikerImpl_AddRef,
112 AntiMonikerImpl_Release,
113 AntiMonikerImpl_GetClassID,
114 AntiMonikerImpl_IsDirty,
115 AntiMonikerImpl_Load,
116 AntiMonikerImpl_Save,
117 AntiMonikerImpl_GetSizeMax,
118 AntiMonikerImpl_BindToObject,
119 AntiMonikerImpl_BindToStorage,
120 AntiMonikerImpl_Reduce,
121 AntiMonikerImpl_ComposeWith,
122 AntiMonikerImpl_Enum,
123 AntiMonikerImpl_IsEqual,
124 AntiMonikerImpl_Hash,
125 AntiMonikerImpl_IsRunning,
126 AntiMonikerImpl_GetTimeOfLastChange,
127 AntiMonikerImpl_Inverse,
128 AntiMonikerImpl_CommonPrefixWith,
129 AntiMonikerImpl_RelativePathTo,
130 AntiMonikerImpl_GetDisplayName,
131 AntiMonikerImpl_ParseDisplayName,
132 AntiMonikerImpl_IsSystemMoniker
135 /********************************************************************************/
136 /* Virtual function table for the IROTData class. */
137 static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
139 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
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 ICOM_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 ICOM_THIS(AntiMonikerImpl,iface);
189 TRACE("(%p)\n",This);
191 return ++(This->ref);
194 /******************************************************************************
195 * AntiMoniker_Release
196 ******************************************************************************/
197 ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface)
199 ICOM_THIS(AntiMonikerImpl,iface);
201 TRACE("(%p)\n",This);
205 /* destroy the object if there's no more reference on it */
208 AntiMonikerImpl_Destroy(This);
215 /******************************************************************************
216 * AntiMoniker_GetClassID
217 ******************************************************************************/
218 HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
220 TRACE("(%p,%p),stub!\n",iface,pClassID);
225 *pClassID = CLSID_AntiMoniker;
230 /******************************************************************************
231 * AntiMoniker_IsDirty
232 ******************************************************************************/
233 HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface)
235 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
236 method in the OLE-provided moniker interfaces always return S_FALSE because
237 their internal state never changes. */
239 TRACE("(%p)\n",iface);
244 /******************************************************************************
246 ******************************************************************************/
247 HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
249 DWORD constant=1,dwbuffer;
252 /* data read by this function is only a DWORD constant (must be 1) ! */
253 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),NULL);
255 if (SUCCEEDED(res)&& dwbuffer!=constant)
261 /******************************************************************************
263 ******************************************************************************/
264 HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
269 /* data written by this function is only a DWORD constant set to 1 ! */
270 res=IStream_Write(pStm,&constant,sizeof(constant),NULL);
275 /******************************************************************************
276 * AntiMoniker_GetSizeMax
277 ******************************************************************************/
278 HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface,
279 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
281 TRACE("(%p,%p)\n",iface,pcbSize);
286 /* for more details see AntiMonikerImpl_Save coments */
288 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
289 /* more than the number of bytes used by AntiMoniker::Save function */
290 pcbSize->u.LowPart = sizeof(DWORD)+16;
292 pcbSize->u.HighPart=0;
297 /******************************************************************************
298 * AntiMoniker_Construct (local function)
299 *******************************************************************************/
300 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* This)
303 TRACE("(%p)\n",This);
305 /* Initialize the virtual fgunction table. */
306 This->lpvtbl1 = &VT_AntiMonikerImpl;
307 This->lpvtbl2 = &VT_ROTDataImpl;
313 /******************************************************************************
314 * AntiMoniker_Destroy (local function)
315 *******************************************************************************/
316 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* This)
318 TRACE("(%p)\n",This);
320 return HeapFree(GetProcessHeap(),0,This);
323 /******************************************************************************
324 * AntiMoniker_BindToObject
325 ******************************************************************************/
326 HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,
332 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
336 /******************************************************************************
337 * AntiMoniker_BindToStorage
338 ******************************************************************************/
339 HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,
345 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
349 /******************************************************************************
351 ******************************************************************************/
352 HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,
354 DWORD dwReduceHowFar,
355 IMoniker** ppmkToLeft,
356 IMoniker** ppmkReduced)
358 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
360 if (ppmkReduced==NULL)
363 AntiMonikerImpl_AddRef(iface);
367 return MK_S_REDUCED_TO_SELF;
369 /******************************************************************************
370 * AntiMoniker_ComposeWith
371 ******************************************************************************/
372 HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,
374 BOOL fOnlyIfNotGeneric,
375 IMoniker** ppmkComposite)
378 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
380 if ((ppmkComposite==NULL)||(pmkRight==NULL))
385 if (fOnlyIfNotGeneric)
386 return MK_E_NEEDGENERIC;
388 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
391 /******************************************************************************
393 ******************************************************************************/
394 HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
396 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
398 if (ppenumMoniker == NULL)
401 *ppenumMoniker = NULL;
406 /******************************************************************************
407 * AntiMoniker_IsEqual
408 ******************************************************************************/
409 HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
413 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
415 if (pmkOtherMoniker==NULL)
418 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
420 if (mkSys==MKSYS_ANTIMONIKER)
426 /******************************************************************************
428 ******************************************************************************/
429 HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
439 /******************************************************************************
440 * AntiMoniker_IsRunning
441 ******************************************************************************/
442 HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,
445 IMoniker* pmkNewlyRunning)
447 IRunningObjectTable* rot;
450 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
455 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
460 res = IRunningObjectTable_IsRunning(rot,iface);
462 IRunningObjectTable_Release(rot);
467 /******************************************************************************
468 * AntiMoniker_GetTimeOfLastChange
469 ******************************************************************************/
470 HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
475 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
479 /******************************************************************************
480 * AntiMoniker_Inverse
481 ******************************************************************************/
482 HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
484 TRACE("(%p,%p)\n",iface,ppmk);
491 return MK_E_NOINVERSE;
494 /******************************************************************************
495 * AntiMoniker_CommonPrefixWith
496 ******************************************************************************/
497 HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
501 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
503 if(mkSys==MKSYS_ITEMMONIKER){
505 IMoniker_AddRef(iface);
509 IMoniker_AddRef(iface);
514 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
517 /******************************************************************************
518 * AntiMoniker_RelativePathTo
519 ******************************************************************************/
520 HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
522 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
524 if (ppmkRelPath==NULL)
527 IMoniker_AddRef(pmOther);
529 *ppmkRelPath=pmOther;
534 /******************************************************************************
535 * AntiMoniker_GetDisplayName
536 ******************************************************************************/
537 HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,
540 LPOLESTR *ppszDisplayName)
542 WCHAR back[]={'\\','.','.',0};
544 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
546 if (ppszDisplayName==NULL)
549 if (pmkToLeft!=NULL){
550 FIXME("() pmkToLeft!=NULL not implemented \n");
554 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
556 if (*ppszDisplayName==NULL)
557 return E_OUTOFMEMORY;
559 strcpyW(*ppszDisplayName,back);
564 /******************************************************************************
565 * AntiMoniker_ParseDisplayName
566 ******************************************************************************/
567 HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,
570 LPOLESTR pszDisplayName,
574 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
578 /******************************************************************************
579 * AntiMoniker_IsSystemMoniker
580 ******************************************************************************/
581 HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
583 TRACE("(%p,%p)\n",iface,pwdMksys);
588 (*pwdMksys)=MKSYS_ANTIMONIKER;
593 /*******************************************************************************
594 * AntiMonikerIROTData_QueryInterface
595 *******************************************************************************/
596 HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
599 ICOM_THIS_From_IROTData(IMoniker, iface);
601 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
603 return AntiMonikerImpl_QueryInterface(This, riid, ppvObject);
606 /***********************************************************************
607 * AntiMonikerIROTData_AddRef
609 ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
611 ICOM_THIS_From_IROTData(IMoniker, iface);
613 TRACE("(%p)\n",iface);
615 return AntiMonikerImpl_AddRef(This);
618 /***********************************************************************
619 * AntiMonikerIROTData_Release
621 ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
623 ICOM_THIS_From_IROTData(IMoniker, iface);
625 TRACE("(%p)\n",iface);
627 return AntiMonikerImpl_Release(This);
630 /******************************************************************************
631 * AntiMonikerIROTData_GetComparaisonData
632 ******************************************************************************/
633 HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
642 /******************************************************************************
643 * CreateAntiMoniker [OLE32.@]
644 ******************************************************************************/
645 HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
647 AntiMonikerImpl* newAntiMoniker = 0;
649 IID riid=IID_IMoniker;
651 TRACE("(%p)\n",ppmk);
653 newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));
655 if (newAntiMoniker == 0)
656 return STG_E_INSUFFICIENTMEMORY;
658 hr = AntiMonikerImpl_Construct(newAntiMoniker);
662 HeapFree(GetProcessHeap(),0,newAntiMoniker);
666 hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk);