1 /***************************************************************************************
2 * AntiMonikers implementation
4 * Copyright 1999 Noomen Hamza
5 ***************************************************************************************/
10 #include "wine/obj_moniker.h"
11 #include "debugtools.h"
13 DEFAULT_DEBUG_CHANNEL(ole
)
15 /* AntiMoniker data structure */
16 typedef struct AntiMonikerImpl
{
18 ICOM_VTABLE(IMoniker
)* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
20 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
21 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
23 ICOM_VTABLE(IROTData
)* lpvtbl2
; /* VTable relative to the IROTData interface.*/
25 ULONG ref
; /* reference counter for this object */
29 /********************************************************************************/
30 /* AntiMoniker prototype functions : */
32 /* IUnknown prototype functions */
33 static HRESULT WINAPI
AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
);
34 static ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker
* iface
);
35 static ULONG WINAPI
AntiMonikerImpl_Release(IMoniker
* iface
);
37 /* IPersist prototype functions */
38 static HRESULT WINAPI
AntiMonikerImpl_GetClassID(IMoniker
* iface
, CLSID
*pClassID
);
40 /* IPersistStream prototype functions */
41 static HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker
* iface
);
42 static HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker
* iface
, IStream
* pStm
);
43 static HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
);
44 static HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
);
46 /* IMoniker prototype functions */
47 static HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
48 static HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
49 static HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker
* iface
,IBindCtx
* pbc
, DWORD dwReduceHowFar
,IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
);
50 static HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker
* iface
,IMoniker
* pmkRight
,BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
);
51 static HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
);
52 static HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
);
53 static HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
);
54 static HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, IMoniker
* pmkNewlyRunning
);
55 static HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
, FILETIME
* pAntiTime
);
56 static HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
);
57 static HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
, IMoniker
** ppmkPrefix
);
58 static HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
);
59 static HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
);
60 static HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
);
61 static HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
);
63 /********************************************************************************/
64 /* IROTData prototype functions */
66 /* IUnknown prototype functions */
67 static HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData
* iface
,REFIID riid
,VOID
** ppvObject
);
68 static ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
* iface
);
69 static ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
);
71 /* IROTData prototype function */
72 static HRESULT WINAPI
AntiMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,BYTE
* pbData
,ULONG cbMax
,ULONG
* pcbData
);
74 /* Local function used by AntiMoniker implementation */
75 HRESULT WINAPI
AntiMonikerImpl_Construct(AntiMonikerImpl
* iface
);
76 HRESULT WINAPI
AntiMonikerImpl_Destroy(AntiMonikerImpl
* iface
);
78 /********************************************************************************/
79 /* Virtual function table for the AntiMonikerImpl class witch include Ipersist,*/
80 /* IPersistStream and IMoniker functions. */
81 static ICOM_VTABLE(IMoniker
) VT_AntiMonikerImpl
=
83 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
84 AntiMonikerImpl_QueryInterface
,
85 AntiMonikerImpl_AddRef
,
86 AntiMonikerImpl_Release
,
87 AntiMonikerImpl_GetClassID
,
88 AntiMonikerImpl_IsDirty
,
91 AntiMonikerImpl_GetSizeMax
,
92 AntiMonikerImpl_BindToObject
,
93 AntiMonikerImpl_BindToStorage
,
94 AntiMonikerImpl_Reduce
,
95 AntiMonikerImpl_ComposeWith
,
97 AntiMonikerImpl_IsEqual
,
99 AntiMonikerImpl_IsRunning
,
100 AntiMonikerImpl_GetTimeOfLastChange
,
101 AntiMonikerImpl_Inverse
,
102 AntiMonikerImpl_CommonPrefixWith
,
103 AntiMonikerImpl_RelativePathTo
,
104 AntiMonikerImpl_GetDisplayName
,
105 AntiMonikerImpl_ParseDisplayName
,
106 AntiMonikerImpl_IsSystemMoniker
109 /********************************************************************************/
110 /* Virtual function table for the IROTData class. */
111 static ICOM_VTABLE(IROTData
) VT_ROTDataImpl
=
113 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
114 AntiMonikerROTDataImpl_QueryInterface
,
115 AntiMonikerROTDataImpl_AddRef
,
116 AntiMonikerROTDataImpl_Release
,
117 AntiMonikerROTDataImpl_GetComparaisonData
120 /*******************************************************************************
121 * AntiMoniker_QueryInterface
122 *******************************************************************************/
123 HRESULT WINAPI
AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
125 ICOM_THIS(AntiMonikerImpl
,iface
);
127 TRACE("(%p,%p,%p)\n",This
,riid
,ppvObject
);
129 /* Perform a sanity check on the parameters.*/
130 if ( (This
==0) || (ppvObject
==0) )
133 /* Initialize the return parameter */
136 /* Compare the riid with the interface IDs implemented by this object.*/
137 if (IsEqualIID(&IID_IUnknown
, riid
) ||
138 IsEqualIID(&IID_IPersist
, riid
) ||
139 IsEqualIID(&IID_IPersistStream
, riid
) ||
140 IsEqualIID(&IID_IMoniker
, riid
)
143 else if (IsEqualIID(&IID_IROTData
, riid
))
144 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
146 /* Check that we obtained an interface.*/
148 return E_NOINTERFACE
;
150 /* Query Interface always increases the reference count by one when it is successful */
151 AntiMonikerImpl_AddRef(iface
);
156 /******************************************************************************
158 ******************************************************************************/
159 ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker
* iface
)
161 ICOM_THIS(AntiMonikerImpl
,iface
);
163 TRACE("(%p)\n",This
);
165 return ++(This
->ref
);
168 /******************************************************************************
169 * AntiMoniker_Release
170 ******************************************************************************/
171 ULONG WINAPI
AntiMonikerImpl_Release(IMoniker
* iface
)
173 ICOM_THIS(AntiMonikerImpl
,iface
);
175 TRACE("(%p)\n",This
);
179 /* destroy the object if there's no more reference on it */
182 AntiMonikerImpl_Destroy(This
);
189 /******************************************************************************
190 * AntiMoniker_GetClassID
191 ******************************************************************************/
192 HRESULT WINAPI
AntiMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
194 TRACE("(%p,%p),stub!\n",iface
,pClassID
);
199 *pClassID
= CLSID_AntiMoniker
;
204 /******************************************************************************
205 * AntiMoniker_IsDirty
206 ******************************************************************************/
207 HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker
* iface
)
209 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
210 method in the OLE-provided moniker interfaces always return S_FALSE because
211 their internal state never changes. */
213 TRACE("(%p)\n",iface
);
218 /******************************************************************************
220 ******************************************************************************/
221 HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
223 DWORD constant
=1,dwbuffer
;
226 /* data read by this function is only a DWORD constant (must be 1) ! */
227 res
=IStream_Read(pStm
,&dwbuffer
,sizeof(DWORD
),NULL
);
229 if (SUCCEEDED(res
)&& dwbuffer
!=constant
)
235 /******************************************************************************
237 ******************************************************************************/
238 HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker
* iface
,IStream
* pStm
,BOOL fClearDirty
)
243 /* data writen by this function is only a DWORD constant seted to 1 ! */
244 res
=IStream_Write(pStm
,&constant
,sizeof(constant
),NULL
);
249 /******************************************************************************
250 * AntiMoniker_GetSizeMax
251 ******************************************************************************/
252 HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker
* iface
,
253 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
255 TRACE("(%p,%p)\n",iface
,pcbSize
);
260 /* for more details see AntiMonikerImpl_Save coments */
262 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
263 /* more than the number of bytes used by AntiMoniker::Save function */
264 pcbSize
->s
.LowPart
= sizeof(DWORD
)+16;
266 pcbSize
->s
.HighPart
=0;
271 /******************************************************************************
272 * AntiMoniker_Construct (local function)
273 *******************************************************************************/
274 HRESULT WINAPI
AntiMonikerImpl_Construct(AntiMonikerImpl
* This
)
277 TRACE("(%p)\n",This
);
279 /* Initialize the virtual fgunction table. */
280 This
->lpvtbl1
= &VT_AntiMonikerImpl
;
281 This
->lpvtbl2
= &VT_ROTDataImpl
;
287 /******************************************************************************
288 * AntiMoniker_Destroy (local function)
289 *******************************************************************************/
290 HRESULT WINAPI
AntiMonikerImpl_Destroy(AntiMonikerImpl
* This
)
292 TRACE("(%p)\n",This
);
294 return HeapFree(GetProcessHeap(),0,This
);
297 /******************************************************************************
298 * AntiMoniker_BindToObject
299 ******************************************************************************/
300 HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker
* iface
,
306 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
310 /******************************************************************************
311 * AntiMoniker_BindToStorage
312 ******************************************************************************/
313 HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker
* iface
,
319 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
323 /******************************************************************************
325 ******************************************************************************/
326 HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker
* iface
,
328 DWORD dwReduceHowFar
,
329 IMoniker
** ppmkToLeft
,
330 IMoniker
** ppmkReduced
)
332 TRACE("(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
334 if (ppmkReduced
==NULL
)
337 AntiMonikerImpl_AddRef(iface
);
341 return MK_S_REDUCED_TO_SELF
;
343 /******************************************************************************
344 * AntiMoniker_ComposeWith
345 ******************************************************************************/
346 HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker
* iface
,
348 BOOL fOnlyIfNotGeneric
,
349 IMoniker
** ppmkComposite
)
352 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
354 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
359 if (fOnlyIfNotGeneric
)
360 return MK_E_NEEDGENERIC
;
362 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
365 /******************************************************************************
367 ******************************************************************************/
368 HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
370 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
372 if (ppenumMoniker
== NULL
)
375 *ppenumMoniker
= NULL
;
380 /******************************************************************************
381 * AntiMoniker_IsEqual
382 ******************************************************************************/
383 HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
387 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
389 if (pmkOtherMoniker
==NULL
)
392 IMoniker_IsSystemMoniker(pmkOtherMoniker
,&mkSys
);
394 if (mkSys
==MKSYS_ANTIMONIKER
)
400 /******************************************************************************
402 ******************************************************************************/
403 HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
413 /******************************************************************************
414 * AntiMoniker_IsRunning
415 ******************************************************************************/
416 HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker
* iface
,
419 IMoniker
* pmkNewlyRunning
)
421 IRunningObjectTable
* rot
;
424 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
429 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
434 res
= IRunningObjectTable_IsRunning(rot
,iface
);
436 IRunningObjectTable_Release(rot
);
441 /******************************************************************************
442 * AntiMoniker_GetTimeOfLastChange
443 ******************************************************************************/
444 HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
449 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pAntiTime
);
453 /******************************************************************************
454 * AntiMoniker_Inverse
455 ******************************************************************************/
456 HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
458 TRACE("(%p,%p)\n",iface
,ppmk
);
465 return MK_E_NOINVERSE
;
468 /******************************************************************************
469 * AntiMoniker_CommonPrefixWith
470 ******************************************************************************/
471 HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
475 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
477 if(mkSys
==MKSYS_ITEMMONIKER
){
479 IMoniker_AddRef(iface
);
483 IMoniker_AddRef(iface
);
488 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
491 /******************************************************************************
492 * AntiMoniker_RelativePathTo
493 ******************************************************************************/
494 HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
496 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
498 if (ppmkRelPath
==NULL
)
501 IMoniker_AddRef(pmOther
);
503 *ppmkRelPath
=pmOther
;
508 /******************************************************************************
509 * AntiMoniker_GetDisplayName
510 ******************************************************************************/
511 HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker
* iface
,
514 LPOLESTR
*ppszDisplayName
)
516 WCHAR back
[]={'\\','.','.',0};
518 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
520 if (ppszDisplayName
==NULL
)
523 if (pmkToLeft
!=NULL
){
524 FIXME("() pmkToLeft!=NULL not implemented \n");
528 *ppszDisplayName
=CoTaskMemAlloc(sizeof(back
));
530 if (*ppszDisplayName
==NULL
)
531 return E_OUTOFMEMORY
;
533 lstrcpyW(*ppszDisplayName
,back
);
538 /******************************************************************************
539 * AntiMoniker_ParseDisplayName
540 ******************************************************************************/
541 HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
,
544 LPOLESTR pszDisplayName
,
548 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pszDisplayName
,pchEaten
,ppmkOut
);
552 /******************************************************************************
553 * AntiMoniker_IsSystemMonker
554 ******************************************************************************/
555 HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
557 TRACE("(%p,%p)\n",iface
,pwdMksys
);
562 (*pwdMksys
)=MKSYS_ANTIMONIKER
;
567 /*******************************************************************************
568 * AntiMonikerIROTData_QueryInterface
569 *******************************************************************************/
570 HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
573 ICOM_THIS_From_IROTData(IMoniker
, iface
);
575 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
577 return AntiMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
580 /***********************************************************************
581 * AntiMonikerIROTData_AddRef
583 ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
*iface
)
585 ICOM_THIS_From_IROTData(IMoniker
, iface
);
587 TRACE("(%p)\n",iface
);
589 return AntiMonikerImpl_AddRef(This
);
592 /***********************************************************************
593 * AntiMonikerIROTData_Release
595 ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
)
597 ICOM_THIS_From_IROTData(IMoniker
, iface
);
599 TRACE("(%p)\n",iface
);
601 return AntiMonikerImpl_Release(This
);
604 /******************************************************************************
605 * AntiMonikerIROTData_GetComparaisonData
606 ******************************************************************************/
607 HRESULT WINAPI
AntiMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,
616 /******************************************************************************
617 * CreateAntiMoniker [OLE.55]
618 ******************************************************************************/
619 HRESULT WINAPI
CreateAntiMoniker(LPMONIKER
* ppmk
)
621 AntiMonikerImpl
* newAntiMoniker
= 0;
623 IID riid
=IID_IMoniker
;
625 TRACE("(%p)\n",ppmk
);
627 newAntiMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl
));
629 if (newAntiMoniker
== 0)
630 return STG_E_INSUFFICIENTMEMORY
;
632 hr
= AntiMonikerImpl_Construct(newAntiMoniker
);
636 HeapFree(GetProcessHeap(),0,newAntiMoniker
);
640 hr
= AntiMonikerImpl_QueryInterface((IMoniker
*)newAntiMoniker
,&riid
,(void**)ppmk
);