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"
29 WINE_DEFAULT_DEBUG_CHANNEL(ole);
31 /* AntiMoniker data structure */
32 typedef struct AntiMonikerImpl{
34 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
36 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
37 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
39 ICOM_VTABLE(IROTData)* lpvtbl2; /* VTable relative to the IROTData interface.*/
41 ULONG ref; /* reference counter for this object */
45 /********************************************************************************/
46 /* AntiMoniker prototype functions : */
48 /* IUnknown prototype functions */
49 static HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
50 static ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface);
51 static ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface);
53 /* IPersist prototype functions */
54 static HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
56 /* IPersistStream prototype functions */
57 static HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface);
58 static HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface, IStream* pStm);
59 static HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
60 static HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
62 /* IMoniker prototype functions */
63 static HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
64 static HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
65 static HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
66 static HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
67 static HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
68 static HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
69 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
70 static HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
71 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pAntiTime);
72 static HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
73 static HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
74 static HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
75 static HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
76 static HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
77 static HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
79 /********************************************************************************/
80 /* IROTData prototype functions */
82 /* IUnknown prototype functions */
83 static HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
84 static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData* iface);
85 static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface);
87 /* IROTData prototype function */
88 static HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
90 /* Local function used by AntiMoniker implementation */
91 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* iface);
92 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* iface);
94 /********************************************************************************/
95 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
96 /* IPersistStream and IMoniker functions. */
97 static ICOM_VTABLE(IMoniker) VT_AntiMonikerImpl =
99 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
100 AntiMonikerImpl_QueryInterface,
101 AntiMonikerImpl_AddRef,
102 AntiMonikerImpl_Release,
103 AntiMonikerImpl_GetClassID,
104 AntiMonikerImpl_IsDirty,
105 AntiMonikerImpl_Load,
106 AntiMonikerImpl_Save,
107 AntiMonikerImpl_GetSizeMax,
108 AntiMonikerImpl_BindToObject,
109 AntiMonikerImpl_BindToStorage,
110 AntiMonikerImpl_Reduce,
111 AntiMonikerImpl_ComposeWith,
112 AntiMonikerImpl_Enum,
113 AntiMonikerImpl_IsEqual,
114 AntiMonikerImpl_Hash,
115 AntiMonikerImpl_IsRunning,
116 AntiMonikerImpl_GetTimeOfLastChange,
117 AntiMonikerImpl_Inverse,
118 AntiMonikerImpl_CommonPrefixWith,
119 AntiMonikerImpl_RelativePathTo,
120 AntiMonikerImpl_GetDisplayName,
121 AntiMonikerImpl_ParseDisplayName,
122 AntiMonikerImpl_IsSystemMoniker
125 /********************************************************************************/
126 /* Virtual function table for the IROTData class. */
127 static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
129 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
130 AntiMonikerROTDataImpl_QueryInterface,
131 AntiMonikerROTDataImpl_AddRef,
132 AntiMonikerROTDataImpl_Release,
133 AntiMonikerROTDataImpl_GetComparaisonData
136 /*******************************************************************************
137 * AntiMoniker_QueryInterface
138 *******************************************************************************/
139 HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
141 ICOM_THIS(AntiMonikerImpl,iface);
143 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
145 /* Perform a sanity check on the parameters.*/
146 if ( (This==0) || (ppvObject==0) )
149 /* Initialize the return parameter */
152 /* Compare the riid with the interface IDs implemented by this object.*/
153 if (IsEqualIID(&IID_IUnknown, riid) ||
154 IsEqualIID(&IID_IPersist, riid) ||
155 IsEqualIID(&IID_IPersistStream, riid) ||
156 IsEqualIID(&IID_IMoniker, riid)
159 else if (IsEqualIID(&IID_IROTData, riid))
160 *ppvObject = (IROTData*)&(This->lpvtbl2);
162 /* Check that we obtained an interface.*/
164 return E_NOINTERFACE;
166 /* Query Interface always increases the reference count by one when it is successful */
167 AntiMonikerImpl_AddRef(iface);
172 /******************************************************************************
174 ******************************************************************************/
175 ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface)
177 ICOM_THIS(AntiMonikerImpl,iface);
179 TRACE("(%p)\n",This);
181 return ++(This->ref);
184 /******************************************************************************
185 * AntiMoniker_Release
186 ******************************************************************************/
187 ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface)
189 ICOM_THIS(AntiMonikerImpl,iface);
191 TRACE("(%p)\n",This);
195 /* destroy the object if there's no more reference on it */
198 AntiMonikerImpl_Destroy(This);
205 /******************************************************************************
206 * AntiMoniker_GetClassID
207 ******************************************************************************/
208 HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
210 TRACE("(%p,%p),stub!\n",iface,pClassID);
215 *pClassID = CLSID_AntiMoniker;
220 /******************************************************************************
221 * AntiMoniker_IsDirty
222 ******************************************************************************/
223 HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface)
225 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
226 method in the OLE-provided moniker interfaces always return S_FALSE because
227 their internal state never changes. */
229 TRACE("(%p)\n",iface);
234 /******************************************************************************
236 ******************************************************************************/
237 HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
239 DWORD constant=1,dwbuffer;
242 /* data read by this function is only a DWORD constant (must be 1) ! */
243 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),NULL);
245 if (SUCCEEDED(res)&& dwbuffer!=constant)
251 /******************************************************************************
253 ******************************************************************************/
254 HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
259 /* data writen by this function is only a DWORD constant seted to 1 ! */
260 res=IStream_Write(pStm,&constant,sizeof(constant),NULL);
265 /******************************************************************************
266 * AntiMoniker_GetSizeMax
267 ******************************************************************************/
268 HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface,
269 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
271 TRACE("(%p,%p)\n",iface,pcbSize);
276 /* for more details see AntiMonikerImpl_Save coments */
278 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
279 /* more than the number of bytes used by AntiMoniker::Save function */
280 pcbSize->s.LowPart = sizeof(DWORD)+16;
282 pcbSize->s.HighPart=0;
287 /******************************************************************************
288 * AntiMoniker_Construct (local function)
289 *******************************************************************************/
290 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* This)
293 TRACE("(%p)\n",This);
295 /* Initialize the virtual fgunction table. */
296 This->lpvtbl1 = &VT_AntiMonikerImpl;
297 This->lpvtbl2 = &VT_ROTDataImpl;
303 /******************************************************************************
304 * AntiMoniker_Destroy (local function)
305 *******************************************************************************/
306 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* This)
308 TRACE("(%p)\n",This);
310 return HeapFree(GetProcessHeap(),0,This);
313 /******************************************************************************
314 * AntiMoniker_BindToObject
315 ******************************************************************************/
316 HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,
322 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
326 /******************************************************************************
327 * AntiMoniker_BindToStorage
328 ******************************************************************************/
329 HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,
335 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
339 /******************************************************************************
341 ******************************************************************************/
342 HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,
344 DWORD dwReduceHowFar,
345 IMoniker** ppmkToLeft,
346 IMoniker** ppmkReduced)
348 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
350 if (ppmkReduced==NULL)
353 AntiMonikerImpl_AddRef(iface);
357 return MK_S_REDUCED_TO_SELF;
359 /******************************************************************************
360 * AntiMoniker_ComposeWith
361 ******************************************************************************/
362 HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,
364 BOOL fOnlyIfNotGeneric,
365 IMoniker** ppmkComposite)
368 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
370 if ((ppmkComposite==NULL)||(pmkRight==NULL))
375 if (fOnlyIfNotGeneric)
376 return MK_E_NEEDGENERIC;
378 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
381 /******************************************************************************
383 ******************************************************************************/
384 HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
386 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
388 if (ppenumMoniker == NULL)
391 *ppenumMoniker = NULL;
396 /******************************************************************************
397 * AntiMoniker_IsEqual
398 ******************************************************************************/
399 HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
403 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
405 if (pmkOtherMoniker==NULL)
408 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
410 if (mkSys==MKSYS_ANTIMONIKER)
416 /******************************************************************************
418 ******************************************************************************/
419 HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
429 /******************************************************************************
430 * AntiMoniker_IsRunning
431 ******************************************************************************/
432 HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,
435 IMoniker* pmkNewlyRunning)
437 IRunningObjectTable* rot;
440 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
445 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
450 res = IRunningObjectTable_IsRunning(rot,iface);
452 IRunningObjectTable_Release(rot);
457 /******************************************************************************
458 * AntiMoniker_GetTimeOfLastChange
459 ******************************************************************************/
460 HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
465 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
469 /******************************************************************************
470 * AntiMoniker_Inverse
471 ******************************************************************************/
472 HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
474 TRACE("(%p,%p)\n",iface,ppmk);
481 return MK_E_NOINVERSE;
484 /******************************************************************************
485 * AntiMoniker_CommonPrefixWith
486 ******************************************************************************/
487 HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
491 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
493 if(mkSys==MKSYS_ITEMMONIKER){
495 IMoniker_AddRef(iface);
499 IMoniker_AddRef(iface);
504 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
507 /******************************************************************************
508 * AntiMoniker_RelativePathTo
509 ******************************************************************************/
510 HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
512 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
514 if (ppmkRelPath==NULL)
517 IMoniker_AddRef(pmOther);
519 *ppmkRelPath=pmOther;
524 /******************************************************************************
525 * AntiMoniker_GetDisplayName
526 ******************************************************************************/
527 HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,
530 LPOLESTR *ppszDisplayName)
532 WCHAR back[]={'\\','.','.',0};
534 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
536 if (ppszDisplayName==NULL)
539 if (pmkToLeft!=NULL){
540 FIXME("() pmkToLeft!=NULL not implemented \n");
544 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
546 if (*ppszDisplayName==NULL)
547 return E_OUTOFMEMORY;
549 strcpyW(*ppszDisplayName,back);
554 /******************************************************************************
555 * AntiMoniker_ParseDisplayName
556 ******************************************************************************/
557 HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,
560 LPOLESTR pszDisplayName,
564 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
568 /******************************************************************************
569 * AntiMoniker_IsSystemMoniker
570 ******************************************************************************/
571 HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
573 TRACE("(%p,%p)\n",iface,pwdMksys);
578 (*pwdMksys)=MKSYS_ANTIMONIKER;
583 /*******************************************************************************
584 * AntiMonikerIROTData_QueryInterface
585 *******************************************************************************/
586 HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
589 ICOM_THIS_From_IROTData(IMoniker, iface);
591 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
593 return AntiMonikerImpl_QueryInterface(This, riid, ppvObject);
596 /***********************************************************************
597 * AntiMonikerIROTData_AddRef
599 ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
601 ICOM_THIS_From_IROTData(IMoniker, iface);
603 TRACE("(%p)\n",iface);
605 return AntiMonikerImpl_AddRef(This);
608 /***********************************************************************
609 * AntiMonikerIROTData_Release
611 ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
613 ICOM_THIS_From_IROTData(IMoniker, iface);
615 TRACE("(%p)\n",iface);
617 return AntiMonikerImpl_Release(This);
620 /******************************************************************************
621 * AntiMonikerIROTData_GetComparaisonData
622 ******************************************************************************/
623 HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
632 /******************************************************************************
633 * CreateAntiMoniker [OLE32.51]
634 ******************************************************************************/
635 HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
637 AntiMonikerImpl* newAntiMoniker = 0;
639 IID riid=IID_IMoniker;
641 TRACE("(%p)\n",ppmk);
643 newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));
645 if (newAntiMoniker == 0)
646 return STG_E_INSUFFICIENTMEMORY;
648 hr = AntiMonikerImpl_Construct(newAntiMoniker);
652 HeapFree(GetProcessHeap(),0,newAntiMoniker);
656 hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk);