1 /***************************************************************************************
2 * AntiMonikers implementation
4 * Copyright 1999 Noomen Hamza
5 ***************************************************************************************/
15 #include "wine/obj_inplace.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(const 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 AntiMonikerImpl_QueryInterface
,
88 AntiMonikerImpl_AddRef
,
89 AntiMonikerImpl_Release
,
90 AntiMonikerImpl_GetClassID
,
91 AntiMonikerImpl_IsDirty
,
94 AntiMonikerImpl_GetSizeMax
,
95 AntiMonikerImpl_BindToObject
,
96 AntiMonikerImpl_BindToStorage
,
97 AntiMonikerImpl_Reduce
,
98 AntiMonikerImpl_ComposeWith
,
100 AntiMonikerImpl_IsEqual
,
101 AntiMonikerImpl_Hash
,
102 AntiMonikerImpl_IsRunning
,
103 AntiMonikerImpl_GetTimeOfLastChange
,
104 AntiMonikerImpl_Inverse
,
105 AntiMonikerImpl_CommonPrefixWith
,
106 AntiMonikerImpl_RelativePathTo
,
107 AntiMonikerImpl_GetDisplayName
,
108 AntiMonikerImpl_ParseDisplayName
,
109 AntiMonikerImpl_IsSystemMoniker
112 /********************************************************************************/
113 /* Virtual function table for the IROTData class. */
114 static ICOM_VTABLE(IROTData
) VT_ROTDataImpl
=
116 AntiMonikerROTDataImpl_QueryInterface
,
117 AntiMonikerROTDataImpl_AddRef
,
118 AntiMonikerROTDataImpl_Release
,
119 AntiMonikerROTDataImpl_GetComparaisonData
122 /*******************************************************************************
123 * AntiMoniker_QueryInterface
124 *******************************************************************************/
125 HRESULT WINAPI
AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
127 ICOM_THIS(AntiMonikerImpl
,iface
);
129 TRACE(ole
,"(%p,%p,%p)\n",This
,riid
,ppvObject
);
131 /* Perform a sanity check on the parameters.*/
132 if ( (This
==0) || (ppvObject
==0) )
135 /* Initialize the return parameter */
138 /* Compare the riid with the interface IDs implemented by this object.*/
139 if (IsEqualIID(&IID_IUnknown
, riid
) ||
140 IsEqualIID(&IID_IPersist
, riid
) ||
141 IsEqualIID(&IID_IPersistStream
, riid
) ||
142 IsEqualIID(&IID_IMoniker
, riid
)
145 else if (IsEqualIID(&IID_IROTData
, riid
))
146 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
148 /* Check that we obtained an interface.*/
150 return E_NOINTERFACE
;
152 /* Query Interface always increases the reference count by one when it is successful */
153 AntiMonikerImpl_AddRef(iface
);
158 /******************************************************************************
160 ******************************************************************************/
161 ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker
* iface
)
163 ICOM_THIS(AntiMonikerImpl
,iface
);
165 TRACE(ole
,"(%p)\n",This
);
167 return ++(This
->ref
);
170 /******************************************************************************
171 * AntiMoniker_Release
172 ******************************************************************************/
173 ULONG WINAPI
AntiMonikerImpl_Release(IMoniker
* iface
)
175 ICOM_THIS(AntiMonikerImpl
,iface
);
177 TRACE(ole
,"(%p)\n",This
);
181 /* destroy the object if there's no more reference on it */
184 AntiMonikerImpl_Destroy(This
);
191 /******************************************************************************
192 * AntiMoniker_GetClassID
193 ******************************************************************************/
194 HRESULT WINAPI
AntiMonikerImpl_GetClassID(const IMoniker
* iface
,CLSID
*pClassID
)
196 TRACE(ole
,"(%p,%p),stub!\n",iface
,pClassID
);
201 *pClassID
= CLSID_AntiMoniker
;
206 /******************************************************************************
207 * AntiMoniker_IsDirty
208 ******************************************************************************/
209 HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker
* iface
)
211 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
212 method in the OLE-provided moniker interfaces always return S_FALSE because
213 their internal state never changes. */
215 TRACE(ole
,"(%p)\n",iface
);
220 /******************************************************************************
222 ******************************************************************************/
223 HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
225 DWORD constant
=1,dwbuffer
;
228 /* data read by this function is only a DWORD constant (must be 1) ! */
229 res
=IStream_Read(pStm
,&dwbuffer
,sizeof(DWORD
),NULL
);
231 if (SUCCEEDED(res
)&& dwbuffer
!=constant
)
237 /******************************************************************************
239 ******************************************************************************/
240 HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker
* iface
,IStream
* pStm
,BOOL fClearDirty
)
245 /* data writen by this function is only a DWORD constant seted to 1 ! */
246 res
=IStream_Write(pStm
,&constant
,sizeof(constant
),NULL
);
251 /******************************************************************************
252 * AntiMoniker_GetSizeMax
253 ******************************************************************************/
254 HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker
* iface
,
255 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
257 TRACE(ole
,"(%p,%p)\n",iface
,pcbSize
);
262 /* for more details see AntiMonikerImpl_Save coments */
264 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
265 /* more than the number of bytes used by AntiMoniker::Save function */
266 pcbSize
->LowPart
= sizeof(DWORD
)+16;
273 /******************************************************************************
274 * AntiMoniker_Construct (local function)
275 *******************************************************************************/
276 HRESULT WINAPI
AntiMonikerImpl_Construct(AntiMonikerImpl
* This
)
279 TRACE(ole
,"(%p)\n",This
);
281 /* Initialize the virtual fgunction table. */
282 This
->lpvtbl1
= &VT_AntiMonikerImpl
;
283 This
->lpvtbl2
= &VT_ROTDataImpl
;
289 /******************************************************************************
290 * AntiMoniker_Destroy (local function)
291 *******************************************************************************/
292 HRESULT WINAPI
AntiMonikerImpl_Destroy(AntiMonikerImpl
* This
)
294 TRACE(ole
,"(%p)\n",This
);
296 return HeapFree(GetProcessHeap(),0,This
);
299 /******************************************************************************
300 * AntiMoniker_BindToObject
301 ******************************************************************************/
302 HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker
* iface
,
308 TRACE(ole
,"(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
312 /******************************************************************************
313 * AntiMoniker_BindToStorage
314 ******************************************************************************/
315 HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker
* iface
,
321 TRACE(ole
,"(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
325 /******************************************************************************
327 ******************************************************************************/
328 HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker
* iface
,
330 DWORD dwReduceHowFar
,
331 IMoniker
** ppmkToLeft
,
332 IMoniker
** ppmkReduced
)
334 TRACE(ole
,"(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
336 if (ppmkReduced
==NULL
)
339 AntiMonikerImpl_AddRef(iface
);
343 return MK_S_REDUCED_TO_SELF
;
345 /******************************************************************************
346 * AntiMoniker_ComposeWith
347 ******************************************************************************/
348 HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker
* iface
,
350 BOOL fOnlyIfNotGeneric
,
351 IMoniker
** ppmkComposite
)
354 TRACE(ole
,"(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
356 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
361 if (fOnlyIfNotGeneric
)
362 return MK_E_NEEDGENERIC
;
364 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
367 /******************************************************************************
369 ******************************************************************************/
370 HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
372 TRACE(ole
,"(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
374 if (ppenumMoniker
== NULL
)
377 *ppenumMoniker
= NULL
;
382 /******************************************************************************
383 * AntiMoniker_IsEqual
384 ******************************************************************************/
385 HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
389 TRACE(ole
,"(%p,%p)\n",iface
,pmkOtherMoniker
);
391 if (pmkOtherMoniker
==NULL
)
394 IMoniker_IsSystemMoniker(pmkOtherMoniker
,&mkSys
);
396 if (mkSys
==MKSYS_ANTIMONIKER
)
402 /******************************************************************************
404 ******************************************************************************/
405 HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
415 /******************************************************************************
416 * AntiMoniker_IsRunning
417 ******************************************************************************/
418 HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker
* iface
,
421 IMoniker
* pmkNewlyRunning
)
423 IRunningObjectTable
* rot
;
426 TRACE(ole
,"(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
431 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
436 res
= IRunningObjectTable_IsRunning(rot
,iface
);
438 IRunningObjectTable_Release(rot
);
443 /******************************************************************************
444 * AntiMoniker_GetTimeOfLastChange
445 ******************************************************************************/
446 HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
451 TRACE(ole
,"(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pAntiTime
);
455 /******************************************************************************
456 * AntiMoniker_Inverse
457 ******************************************************************************/
458 HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
460 TRACE(ole
,"(%p,%p)\n",iface
,ppmk
);
467 return MK_E_NOINVERSE
;
470 /******************************************************************************
471 * AntiMoniker_CommonPrefixWith
472 ******************************************************************************/
473 HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
477 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
479 if(mkSys
==MKSYS_ITEMMONIKER
){
481 IMoniker_AddRef(iface
);
485 IMoniker_AddRef(iface
);
490 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
493 /******************************************************************************
494 * AntiMoniker_RelativePathTo
495 ******************************************************************************/
496 HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
498 TRACE(ole
,"(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
500 if (ppmkRelPath
==NULL
)
503 IMoniker_AddRef(pmOther
);
505 *ppmkRelPath
=pmOther
;
510 /******************************************************************************
511 * AntiMoniker_GetDisplayName
512 ******************************************************************************/
513 HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker
* iface
,
516 LPOLESTR
*ppszDisplayName
)
518 WCHAR back
[]={'\\','.','.',0};
520 TRACE(ole
,"(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
522 if (ppszDisplayName
==NULL
)
525 if (pmkToLeft
!=NULL
){
526 FIXME(ole
,"() pmkToLeft!=NULL not implemented \n");
530 *ppszDisplayName
=CoTaskMemAlloc(sizeof(back
));
532 if (*ppszDisplayName
==NULL
)
533 return E_OUTOFMEMORY
;
535 lstrcpyW(*ppszDisplayName
,back
);
540 /******************************************************************************
541 * AntiMoniker_ParseDisplayName
542 ******************************************************************************/
543 HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
,
546 LPOLESTR pszDisplayName
,
550 TRACE(ole
,"(%p,%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pszDisplayName
,pchEaten
,ppmkOut
);
554 /******************************************************************************
555 * AntiMoniker_IsSystemMonker
556 ******************************************************************************/
557 HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
559 TRACE(ole
,"(%p,%p)\n",iface
,pwdMksys
);
564 (*pwdMksys
)=MKSYS_ANTIMONIKER
;
569 /*******************************************************************************
570 * AntiMonikerIROTData_QueryInterface
571 *******************************************************************************/
572 HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
575 ICOM_THIS_From_IROTData(IMoniker
, iface
);
577 TRACE(ole
,"(%p,%p,%p)\n",iface
,riid
,ppvObject
);
579 return AntiMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
582 /***********************************************************************
583 * AntiMonikerIROTData_AddRef
585 ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
*iface
)
587 ICOM_THIS_From_IROTData(IMoniker
, iface
);
589 TRACE(ole
,"(%p)\n",iface
);
591 return AntiMonikerImpl_AddRef(This
);
594 /***********************************************************************
595 * AntiMonikerIROTData_Release
597 ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
)
599 ICOM_THIS_From_IROTData(IMoniker
, iface
);
601 TRACE(ole
,"(%p)\n",iface
);
603 return AntiMonikerImpl_Release(This
);
606 /******************************************************************************
607 * AntiMonikerIROTData_GetComparaisonData
608 ******************************************************************************/
609 HRESULT WINAPI
AntiMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,
614 FIXME(ole
,"(),stub!\n");
618 /******************************************************************************
619 * CreateAntiMoniker [OLE.55]
620 ******************************************************************************/
621 HRESULT WINAPI
CreateAntiMoniker(LPMONIKER
* ppmk
)
623 AntiMonikerImpl
* newAntiMoniker
= 0;
625 IID riid
=IID_IMoniker
;
627 TRACE(ole
,"(%p)\n",ppmk
);
629 newAntiMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl
));
631 if (newAntiMoniker
== 0)
632 return STG_E_INSUFFICIENTMEMORY
;
634 hr
= AntiMonikerImpl_Construct(newAntiMoniker
);
638 HeapFree(GetProcessHeap(),0,newAntiMoniker
);
642 hr
= AntiMonikerImpl_QueryInterface((IMoniker
*)newAntiMoniker
,&riid
,(void**)ppmk
);