1 /***************************************************************************************
2 * AntiMonikers implementation
4 * Copyright 1999 Noomen Hamza
5 ***************************************************************************************/
10 #include "wine/unicode.h"
11 #include "wine/obj_base.h"
12 #include "wine/obj_misc.h"
13 #include "wine/obj_storage.h"
14 #include "wine/obj_moniker.h"
15 #include "debugtools.h"
17 DEFAULT_DEBUG_CHANNEL(ole
);
19 /* AntiMoniker data structure */
20 typedef struct AntiMonikerImpl
{
22 ICOM_VTABLE(IMoniker
)* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
24 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
25 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
27 ICOM_VTABLE(IROTData
)* lpvtbl2
; /* VTable relative to the IROTData interface.*/
29 ULONG ref
; /* reference counter for this object */
33 /********************************************************************************/
34 /* AntiMoniker prototype functions : */
36 /* IUnknown prototype functions */
37 static HRESULT WINAPI
AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
);
38 static ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker
* iface
);
39 static ULONG WINAPI
AntiMonikerImpl_Release(IMoniker
* iface
);
41 /* IPersist prototype functions */
42 static HRESULT WINAPI
AntiMonikerImpl_GetClassID(IMoniker
* iface
, CLSID
*pClassID
);
44 /* IPersistStream prototype functions */
45 static HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker
* iface
);
46 static HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker
* iface
, IStream
* pStm
);
47 static HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
);
48 static HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
);
50 /* IMoniker prototype functions */
51 static HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
52 static HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
53 static HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker
* iface
,IBindCtx
* pbc
, DWORD dwReduceHowFar
,IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
);
54 static HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker
* iface
,IMoniker
* pmkRight
,BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
);
55 static HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
);
56 static HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
);
57 static HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
);
58 static HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, IMoniker
* pmkNewlyRunning
);
59 static HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
, FILETIME
* pAntiTime
);
60 static HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
);
61 static HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
, IMoniker
** ppmkPrefix
);
62 static HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
);
63 static HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
);
64 static HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
);
65 static HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
);
67 /********************************************************************************/
68 /* IROTData prototype functions */
70 /* IUnknown prototype functions */
71 static HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData
* iface
,REFIID riid
,VOID
** ppvObject
);
72 static ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
* iface
);
73 static ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
);
75 /* IROTData prototype function */
76 static HRESULT WINAPI
AntiMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,BYTE
* pbData
,ULONG cbMax
,ULONG
* pcbData
);
78 /* Local function used by AntiMoniker implementation */
79 HRESULT WINAPI
AntiMonikerImpl_Construct(AntiMonikerImpl
* iface
);
80 HRESULT WINAPI
AntiMonikerImpl_Destroy(AntiMonikerImpl
* iface
);
82 /********************************************************************************/
83 /* Virtual function table for the AntiMonikerImpl class witch include Ipersist,*/
84 /* IPersistStream and IMoniker functions. */
85 static ICOM_VTABLE(IMoniker
) VT_AntiMonikerImpl
=
87 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
88 AntiMonikerImpl_QueryInterface
,
89 AntiMonikerImpl_AddRef
,
90 AntiMonikerImpl_Release
,
91 AntiMonikerImpl_GetClassID
,
92 AntiMonikerImpl_IsDirty
,
95 AntiMonikerImpl_GetSizeMax
,
96 AntiMonikerImpl_BindToObject
,
97 AntiMonikerImpl_BindToStorage
,
98 AntiMonikerImpl_Reduce
,
99 AntiMonikerImpl_ComposeWith
,
100 AntiMonikerImpl_Enum
,
101 AntiMonikerImpl_IsEqual
,
102 AntiMonikerImpl_Hash
,
103 AntiMonikerImpl_IsRunning
,
104 AntiMonikerImpl_GetTimeOfLastChange
,
105 AntiMonikerImpl_Inverse
,
106 AntiMonikerImpl_CommonPrefixWith
,
107 AntiMonikerImpl_RelativePathTo
,
108 AntiMonikerImpl_GetDisplayName
,
109 AntiMonikerImpl_ParseDisplayName
,
110 AntiMonikerImpl_IsSystemMoniker
113 /********************************************************************************/
114 /* Virtual function table for the IROTData class. */
115 static ICOM_VTABLE(IROTData
) VT_ROTDataImpl
=
117 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
118 AntiMonikerROTDataImpl_QueryInterface
,
119 AntiMonikerROTDataImpl_AddRef
,
120 AntiMonikerROTDataImpl_Release
,
121 AntiMonikerROTDataImpl_GetComparaisonData
124 /*******************************************************************************
125 * AntiMoniker_QueryInterface
126 *******************************************************************************/
127 HRESULT WINAPI
AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
129 ICOM_THIS(AntiMonikerImpl
,iface
);
131 TRACE("(%p,%p,%p)\n",This
,riid
,ppvObject
);
133 /* Perform a sanity check on the parameters.*/
134 if ( (This
==0) || (ppvObject
==0) )
137 /* Initialize the return parameter */
140 /* Compare the riid with the interface IDs implemented by this object.*/
141 if (IsEqualIID(&IID_IUnknown
, riid
) ||
142 IsEqualIID(&IID_IPersist
, riid
) ||
143 IsEqualIID(&IID_IPersistStream
, riid
) ||
144 IsEqualIID(&IID_IMoniker
, riid
)
147 else if (IsEqualIID(&IID_IROTData
, riid
))
148 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
150 /* Check that we obtained an interface.*/
152 return E_NOINTERFACE
;
154 /* Query Interface always increases the reference count by one when it is successful */
155 AntiMonikerImpl_AddRef(iface
);
160 /******************************************************************************
162 ******************************************************************************/
163 ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker
* iface
)
165 ICOM_THIS(AntiMonikerImpl
,iface
);
167 TRACE("(%p)\n",This
);
169 return ++(This
->ref
);
172 /******************************************************************************
173 * AntiMoniker_Release
174 ******************************************************************************/
175 ULONG WINAPI
AntiMonikerImpl_Release(IMoniker
* iface
)
177 ICOM_THIS(AntiMonikerImpl
,iface
);
179 TRACE("(%p)\n",This
);
183 /* destroy the object if there's no more reference on it */
186 AntiMonikerImpl_Destroy(This
);
193 /******************************************************************************
194 * AntiMoniker_GetClassID
195 ******************************************************************************/
196 HRESULT WINAPI
AntiMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
198 TRACE("(%p,%p),stub!\n",iface
,pClassID
);
203 *pClassID
= CLSID_AntiMoniker
;
208 /******************************************************************************
209 * AntiMoniker_IsDirty
210 ******************************************************************************/
211 HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker
* iface
)
213 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
214 method in the OLE-provided moniker interfaces always return S_FALSE because
215 their internal state never changes. */
217 TRACE("(%p)\n",iface
);
222 /******************************************************************************
224 ******************************************************************************/
225 HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
227 DWORD constant
=1,dwbuffer
;
230 /* data read by this function is only a DWORD constant (must be 1) ! */
231 res
=IStream_Read(pStm
,&dwbuffer
,sizeof(DWORD
),NULL
);
233 if (SUCCEEDED(res
)&& dwbuffer
!=constant
)
239 /******************************************************************************
241 ******************************************************************************/
242 HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker
* iface
,IStream
* pStm
,BOOL fClearDirty
)
247 /* data writen by this function is only a DWORD constant seted to 1 ! */
248 res
=IStream_Write(pStm
,&constant
,sizeof(constant
),NULL
);
253 /******************************************************************************
254 * AntiMoniker_GetSizeMax
255 ******************************************************************************/
256 HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker
* iface
,
257 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
259 TRACE("(%p,%p)\n",iface
,pcbSize
);
264 /* for more details see AntiMonikerImpl_Save coments */
266 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
267 /* more than the number of bytes used by AntiMoniker::Save function */
268 pcbSize
->s
.LowPart
= sizeof(DWORD
)+16;
270 pcbSize
->s
.HighPart
=0;
275 /******************************************************************************
276 * AntiMoniker_Construct (local function)
277 *******************************************************************************/
278 HRESULT WINAPI
AntiMonikerImpl_Construct(AntiMonikerImpl
* This
)
281 TRACE("(%p)\n",This
);
283 /* Initialize the virtual fgunction table. */
284 This
->lpvtbl1
= &VT_AntiMonikerImpl
;
285 This
->lpvtbl2
= &VT_ROTDataImpl
;
291 /******************************************************************************
292 * AntiMoniker_Destroy (local function)
293 *******************************************************************************/
294 HRESULT WINAPI
AntiMonikerImpl_Destroy(AntiMonikerImpl
* This
)
296 TRACE("(%p)\n",This
);
298 return HeapFree(GetProcessHeap(),0,This
);
301 /******************************************************************************
302 * AntiMoniker_BindToObject
303 ******************************************************************************/
304 HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker
* iface
,
310 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
314 /******************************************************************************
315 * AntiMoniker_BindToStorage
316 ******************************************************************************/
317 HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker
* iface
,
323 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
327 /******************************************************************************
329 ******************************************************************************/
330 HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker
* iface
,
332 DWORD dwReduceHowFar
,
333 IMoniker
** ppmkToLeft
,
334 IMoniker
** ppmkReduced
)
336 TRACE("(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
338 if (ppmkReduced
==NULL
)
341 AntiMonikerImpl_AddRef(iface
);
345 return MK_S_REDUCED_TO_SELF
;
347 /******************************************************************************
348 * AntiMoniker_ComposeWith
349 ******************************************************************************/
350 HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker
* iface
,
352 BOOL fOnlyIfNotGeneric
,
353 IMoniker
** ppmkComposite
)
356 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
358 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
363 if (fOnlyIfNotGeneric
)
364 return MK_E_NEEDGENERIC
;
366 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
369 /******************************************************************************
371 ******************************************************************************/
372 HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
374 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
376 if (ppenumMoniker
== NULL
)
379 *ppenumMoniker
= NULL
;
384 /******************************************************************************
385 * AntiMoniker_IsEqual
386 ******************************************************************************/
387 HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
391 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
393 if (pmkOtherMoniker
==NULL
)
396 IMoniker_IsSystemMoniker(pmkOtherMoniker
,&mkSys
);
398 if (mkSys
==MKSYS_ANTIMONIKER
)
404 /******************************************************************************
406 ******************************************************************************/
407 HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
417 /******************************************************************************
418 * AntiMoniker_IsRunning
419 ******************************************************************************/
420 HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker
* iface
,
423 IMoniker
* pmkNewlyRunning
)
425 IRunningObjectTable
* rot
;
428 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
433 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
438 res
= IRunningObjectTable_IsRunning(rot
,iface
);
440 IRunningObjectTable_Release(rot
);
445 /******************************************************************************
446 * AntiMoniker_GetTimeOfLastChange
447 ******************************************************************************/
448 HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
453 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pAntiTime
);
457 /******************************************************************************
458 * AntiMoniker_Inverse
459 ******************************************************************************/
460 HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
462 TRACE("(%p,%p)\n",iface
,ppmk
);
469 return MK_E_NOINVERSE
;
472 /******************************************************************************
473 * AntiMoniker_CommonPrefixWith
474 ******************************************************************************/
475 HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
479 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
481 if(mkSys
==MKSYS_ITEMMONIKER
){
483 IMoniker_AddRef(iface
);
487 IMoniker_AddRef(iface
);
492 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
495 /******************************************************************************
496 * AntiMoniker_RelativePathTo
497 ******************************************************************************/
498 HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
500 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
502 if (ppmkRelPath
==NULL
)
505 IMoniker_AddRef(pmOther
);
507 *ppmkRelPath
=pmOther
;
512 /******************************************************************************
513 * AntiMoniker_GetDisplayName
514 ******************************************************************************/
515 HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker
* iface
,
518 LPOLESTR
*ppszDisplayName
)
520 WCHAR back
[]={'\\','.','.',0};
522 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
524 if (ppszDisplayName
==NULL
)
527 if (pmkToLeft
!=NULL
){
528 FIXME("() pmkToLeft!=NULL not implemented \n");
532 *ppszDisplayName
=CoTaskMemAlloc(sizeof(back
));
534 if (*ppszDisplayName
==NULL
)
535 return E_OUTOFMEMORY
;
537 strcpyW(*ppszDisplayName
,back
);
542 /******************************************************************************
543 * AntiMoniker_ParseDisplayName
544 ******************************************************************************/
545 HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
,
548 LPOLESTR pszDisplayName
,
552 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pszDisplayName
,pchEaten
,ppmkOut
);
556 /******************************************************************************
557 * AntiMoniker_IsSystemMonker
558 ******************************************************************************/
559 HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
561 TRACE("(%p,%p)\n",iface
,pwdMksys
);
566 (*pwdMksys
)=MKSYS_ANTIMONIKER
;
571 /*******************************************************************************
572 * AntiMonikerIROTData_QueryInterface
573 *******************************************************************************/
574 HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
577 ICOM_THIS_From_IROTData(IMoniker
, iface
);
579 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
581 return AntiMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
584 /***********************************************************************
585 * AntiMonikerIROTData_AddRef
587 ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
*iface
)
589 ICOM_THIS_From_IROTData(IMoniker
, iface
);
591 TRACE("(%p)\n",iface
);
593 return AntiMonikerImpl_AddRef(This
);
596 /***********************************************************************
597 * AntiMonikerIROTData_Release
599 ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
)
601 ICOM_THIS_From_IROTData(IMoniker
, iface
);
603 TRACE("(%p)\n",iface
);
605 return AntiMonikerImpl_Release(This
);
608 /******************************************************************************
609 * AntiMonikerIROTData_GetComparaisonData
610 ******************************************************************************/
611 HRESULT WINAPI
AntiMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,
620 /******************************************************************************
621 * CreateAntiMoniker [OLE.55]
622 ******************************************************************************/
623 HRESULT WINAPI
CreateAntiMoniker(LPMONIKER
* ppmk
)
625 AntiMonikerImpl
* newAntiMoniker
= 0;
627 IID riid
=IID_IMoniker
;
629 TRACE("(%p)\n",ppmk
);
631 newAntiMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl
));
633 if (newAntiMoniker
== 0)
634 return STG_E_INSUFFICIENTMEMORY
;
636 hr
= AntiMonikerImpl_Construct(newAntiMoniker
);
640 HeapFree(GetProcessHeap(),0,newAntiMoniker
);
644 hr
= AntiMonikerImpl_QueryInterface((IMoniker
*)newAntiMoniker
,&riid
,(void**)ppmk
);