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 #include "wine/unicode.h"
27 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(ole);
32 const CLSID CLSID_AntiMoniker = {
33 0x305, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
36 /* AntiMoniker data structure */
37 typedef struct AntiMonikerImpl{
39 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
41 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
42 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
44 ICOM_VTABLE(IROTData)* lpvtbl2; /* VTable relative to the IROTData interface.*/
46 ULONG ref; /* reference counter for this object */
50 /********************************************************************************/
51 /* AntiMoniker prototype functions : */
53 /* IUnknown prototype functions */
54 static HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
55 static ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface);
56 static ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface);
58 /* IPersist prototype functions */
59 static HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
61 /* IPersistStream prototype functions */
62 static HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface);
63 static HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface, IStream* pStm);
64 static HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
65 static HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
67 /* IMoniker prototype functions */
68 static HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
69 static HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
70 static HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
71 static HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
72 static HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
73 static HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
74 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
75 static HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
76 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pAntiTime);
77 static HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
78 static HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
79 static HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
80 static HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
81 static HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
82 static HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
84 /********************************************************************************/
85 /* IROTData prototype functions */
87 /* IUnknown prototype functions */
88 static HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
89 static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData* iface);
90 static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface);
92 /* IROTData prototype function */
93 static HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
95 /* Local function used by AntiMoniker implementation */
96 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* iface);
97 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* iface);
99 /********************************************************************************/
100 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
101 /* IPersistStream and IMoniker functions. */
102 static ICOM_VTABLE(IMoniker) VT_AntiMonikerImpl =
104 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
105 AntiMonikerImpl_QueryInterface,
106 AntiMonikerImpl_AddRef,
107 AntiMonikerImpl_Release,
108 AntiMonikerImpl_GetClassID,
109 AntiMonikerImpl_IsDirty,
110 AntiMonikerImpl_Load,
111 AntiMonikerImpl_Save,
112 AntiMonikerImpl_GetSizeMax,
113 AntiMonikerImpl_BindToObject,
114 AntiMonikerImpl_BindToStorage,
115 AntiMonikerImpl_Reduce,
116 AntiMonikerImpl_ComposeWith,
117 AntiMonikerImpl_Enum,
118 AntiMonikerImpl_IsEqual,
119 AntiMonikerImpl_Hash,
120 AntiMonikerImpl_IsRunning,
121 AntiMonikerImpl_GetTimeOfLastChange,
122 AntiMonikerImpl_Inverse,
123 AntiMonikerImpl_CommonPrefixWith,
124 AntiMonikerImpl_RelativePathTo,
125 AntiMonikerImpl_GetDisplayName,
126 AntiMonikerImpl_ParseDisplayName,
127 AntiMonikerImpl_IsSystemMoniker
130 /********************************************************************************/
131 /* Virtual function table for the IROTData class. */
132 static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
134 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
135 AntiMonikerROTDataImpl_QueryInterface,
136 AntiMonikerROTDataImpl_AddRef,
137 AntiMonikerROTDataImpl_Release,
138 AntiMonikerROTDataImpl_GetComparaisonData
141 /*******************************************************************************
142 * AntiMoniker_QueryInterface
143 *******************************************************************************/
144 HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
146 ICOM_THIS(AntiMonikerImpl,iface);
148 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
150 /* Perform a sanity check on the parameters.*/
151 if ( (This==0) || (ppvObject==0) )
154 /* Initialize the return parameter */
157 /* Compare the riid with the interface IDs implemented by this object.*/
158 if (IsEqualIID(&IID_IUnknown, riid) ||
159 IsEqualIID(&IID_IPersist, riid) ||
160 IsEqualIID(&IID_IPersistStream, riid) ||
161 IsEqualIID(&IID_IMoniker, riid)
164 else if (IsEqualIID(&IID_IROTData, riid))
165 *ppvObject = (IROTData*)&(This->lpvtbl2);
167 /* Check that we obtained an interface.*/
169 return E_NOINTERFACE;
171 /* Query Interface always increases the reference count by one when it is successful */
172 AntiMonikerImpl_AddRef(iface);
177 /******************************************************************************
179 ******************************************************************************/
180 ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface)
182 ICOM_THIS(AntiMonikerImpl,iface);
184 TRACE("(%p)\n",This);
186 return ++(This->ref);
189 /******************************************************************************
190 * AntiMoniker_Release
191 ******************************************************************************/
192 ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface)
194 ICOM_THIS(AntiMonikerImpl,iface);
196 TRACE("(%p)\n",This);
200 /* destroy the object if there's no more reference on it */
203 AntiMonikerImpl_Destroy(This);
210 /******************************************************************************
211 * AntiMoniker_GetClassID
212 ******************************************************************************/
213 HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
215 TRACE("(%p,%p),stub!\n",iface,pClassID);
220 *pClassID = CLSID_AntiMoniker;
225 /******************************************************************************
226 * AntiMoniker_IsDirty
227 ******************************************************************************/
228 HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface)
230 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
231 method in the OLE-provided moniker interfaces always return S_FALSE because
232 their internal state never changes. */
234 TRACE("(%p)\n",iface);
239 /******************************************************************************
241 ******************************************************************************/
242 HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
244 DWORD constant=1,dwbuffer;
247 /* data read by this function is only a DWORD constant (must be 1) ! */
248 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),NULL);
250 if (SUCCEEDED(res)&& dwbuffer!=constant)
256 /******************************************************************************
258 ******************************************************************************/
259 HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
264 /* data writen by this function is only a DWORD constant seted to 1 ! */
265 res=IStream_Write(pStm,&constant,sizeof(constant),NULL);
270 /******************************************************************************
271 * AntiMoniker_GetSizeMax
272 ******************************************************************************/
273 HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface,
274 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
276 TRACE("(%p,%p)\n",iface,pcbSize);
281 /* for more details see AntiMonikerImpl_Save coments */
283 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
284 /* more than the number of bytes used by AntiMoniker::Save function */
285 pcbSize->s.LowPart = sizeof(DWORD)+16;
287 pcbSize->s.HighPart=0;
292 /******************************************************************************
293 * AntiMoniker_Construct (local function)
294 *******************************************************************************/
295 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* This)
298 TRACE("(%p)\n",This);
300 /* Initialize the virtual fgunction table. */
301 This->lpvtbl1 = &VT_AntiMonikerImpl;
302 This->lpvtbl2 = &VT_ROTDataImpl;
308 /******************************************************************************
309 * AntiMoniker_Destroy (local function)
310 *******************************************************************************/
311 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* This)
313 TRACE("(%p)\n",This);
315 return HeapFree(GetProcessHeap(),0,This);
318 /******************************************************************************
319 * AntiMoniker_BindToObject
320 ******************************************************************************/
321 HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,
327 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
331 /******************************************************************************
332 * AntiMoniker_BindToStorage
333 ******************************************************************************/
334 HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,
340 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
344 /******************************************************************************
346 ******************************************************************************/
347 HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,
349 DWORD dwReduceHowFar,
350 IMoniker** ppmkToLeft,
351 IMoniker** ppmkReduced)
353 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
355 if (ppmkReduced==NULL)
358 AntiMonikerImpl_AddRef(iface);
362 return MK_S_REDUCED_TO_SELF;
364 /******************************************************************************
365 * AntiMoniker_ComposeWith
366 ******************************************************************************/
367 HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,
369 BOOL fOnlyIfNotGeneric,
370 IMoniker** ppmkComposite)
373 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
375 if ((ppmkComposite==NULL)||(pmkRight==NULL))
380 if (fOnlyIfNotGeneric)
381 return MK_E_NEEDGENERIC;
383 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
386 /******************************************************************************
388 ******************************************************************************/
389 HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
391 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
393 if (ppenumMoniker == NULL)
396 *ppenumMoniker = NULL;
401 /******************************************************************************
402 * AntiMoniker_IsEqual
403 ******************************************************************************/
404 HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
408 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
410 if (pmkOtherMoniker==NULL)
413 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
415 if (mkSys==MKSYS_ANTIMONIKER)
421 /******************************************************************************
423 ******************************************************************************/
424 HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
434 /******************************************************************************
435 * AntiMoniker_IsRunning
436 ******************************************************************************/
437 HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,
440 IMoniker* pmkNewlyRunning)
442 IRunningObjectTable* rot;
445 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
450 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
455 res = IRunningObjectTable_IsRunning(rot,iface);
457 IRunningObjectTable_Release(rot);
462 /******************************************************************************
463 * AntiMoniker_GetTimeOfLastChange
464 ******************************************************************************/
465 HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
470 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
474 /******************************************************************************
475 * AntiMoniker_Inverse
476 ******************************************************************************/
477 HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
479 TRACE("(%p,%p)\n",iface,ppmk);
486 return MK_E_NOINVERSE;
489 /******************************************************************************
490 * AntiMoniker_CommonPrefixWith
491 ******************************************************************************/
492 HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
496 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
498 if(mkSys==MKSYS_ITEMMONIKER){
500 IMoniker_AddRef(iface);
504 IMoniker_AddRef(iface);
509 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
512 /******************************************************************************
513 * AntiMoniker_RelativePathTo
514 ******************************************************************************/
515 HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
517 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
519 if (ppmkRelPath==NULL)
522 IMoniker_AddRef(pmOther);
524 *ppmkRelPath=pmOther;
529 /******************************************************************************
530 * AntiMoniker_GetDisplayName
531 ******************************************************************************/
532 HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,
535 LPOLESTR *ppszDisplayName)
537 WCHAR back[]={'\\','.','.',0};
539 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
541 if (ppszDisplayName==NULL)
544 if (pmkToLeft!=NULL){
545 FIXME("() pmkToLeft!=NULL not implemented \n");
549 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
551 if (*ppszDisplayName==NULL)
552 return E_OUTOFMEMORY;
554 strcpyW(*ppszDisplayName,back);
559 /******************************************************************************
560 * AntiMoniker_ParseDisplayName
561 ******************************************************************************/
562 HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,
565 LPOLESTR pszDisplayName,
569 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
573 /******************************************************************************
574 * AntiMoniker_IsSystemMoniker
575 ******************************************************************************/
576 HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
578 TRACE("(%p,%p)\n",iface,pwdMksys);
583 (*pwdMksys)=MKSYS_ANTIMONIKER;
588 /*******************************************************************************
589 * AntiMonikerIROTData_QueryInterface
590 *******************************************************************************/
591 HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
594 ICOM_THIS_From_IROTData(IMoniker, iface);
596 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
598 return AntiMonikerImpl_QueryInterface(This, riid, ppvObject);
601 /***********************************************************************
602 * AntiMonikerIROTData_AddRef
604 ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
606 ICOM_THIS_From_IROTData(IMoniker, iface);
608 TRACE("(%p)\n",iface);
610 return AntiMonikerImpl_AddRef(This);
613 /***********************************************************************
614 * AntiMonikerIROTData_Release
616 ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
618 ICOM_THIS_From_IROTData(IMoniker, iface);
620 TRACE("(%p)\n",iface);
622 return AntiMonikerImpl_Release(This);
625 /******************************************************************************
626 * AntiMonikerIROTData_GetComparaisonData
627 ******************************************************************************/
628 HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
637 /******************************************************************************
638 * CreateAntiMoniker [OLE32.51]
639 ******************************************************************************/
640 HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
642 AntiMonikerImpl* newAntiMoniker = 0;
644 IID riid=IID_IMoniker;
646 TRACE("(%p)\n",ppmk);
648 newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));
650 if (newAntiMoniker == 0)
651 return STG_E_INSUFFICIENTMEMORY;
653 hr = AntiMonikerImpl_Construct(newAntiMoniker);
657 HeapFree(GetProcessHeap(),0,newAntiMoniker);
661 hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk);