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"
26 #include "wine/obj_base.h"
27 #include "wine/obj_misc.h"
28 #include "wine/obj_storage.h"
29 #include "wine/obj_moniker.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
34 /* AntiMoniker data structure */
35 typedef struct AntiMonikerImpl
{
37 ICOM_VTABLE(IMoniker
)* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
39 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
40 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
42 ICOM_VTABLE(IROTData
)* lpvtbl2
; /* VTable relative to the IROTData interface.*/
44 ULONG ref
; /* reference counter for this object */
48 /********************************************************************************/
49 /* AntiMoniker prototype functions : */
51 /* IUnknown prototype functions */
52 static HRESULT WINAPI
AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
);
53 static ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker
* iface
);
54 static ULONG WINAPI
AntiMonikerImpl_Release(IMoniker
* iface
);
56 /* IPersist prototype functions */
57 static HRESULT WINAPI
AntiMonikerImpl_GetClassID(IMoniker
* iface
, CLSID
*pClassID
);
59 /* IPersistStream prototype functions */
60 static HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker
* iface
);
61 static HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker
* iface
, IStream
* pStm
);
62 static HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
);
63 static HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
);
65 /* IMoniker prototype functions */
66 static HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
67 static HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
68 static HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker
* iface
,IBindCtx
* pbc
, DWORD dwReduceHowFar
,IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
);
69 static HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker
* iface
,IMoniker
* pmkRight
,BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
);
70 static HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
);
71 static HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
);
72 static HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
);
73 static HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, IMoniker
* pmkNewlyRunning
);
74 static HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
, FILETIME
* pAntiTime
);
75 static HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
);
76 static HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
, IMoniker
** ppmkPrefix
);
77 static HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
);
78 static HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
);
79 static HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
);
80 static HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
);
82 /********************************************************************************/
83 /* IROTData prototype functions */
85 /* IUnknown prototype functions */
86 static HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData
* iface
,REFIID riid
,VOID
** ppvObject
);
87 static ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
* iface
);
88 static ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
);
90 /* IROTData prototype function */
91 static HRESULT WINAPI
AntiMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,BYTE
* pbData
,ULONG cbMax
,ULONG
* pcbData
);
93 /* Local function used by AntiMoniker implementation */
94 HRESULT WINAPI
AntiMonikerImpl_Construct(AntiMonikerImpl
* iface
);
95 HRESULT WINAPI
AntiMonikerImpl_Destroy(AntiMonikerImpl
* iface
);
97 /********************************************************************************/
98 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
99 /* IPersistStream and IMoniker functions. */
100 static ICOM_VTABLE(IMoniker
) VT_AntiMonikerImpl
=
102 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
103 AntiMonikerImpl_QueryInterface
,
104 AntiMonikerImpl_AddRef
,
105 AntiMonikerImpl_Release
,
106 AntiMonikerImpl_GetClassID
,
107 AntiMonikerImpl_IsDirty
,
108 AntiMonikerImpl_Load
,
109 AntiMonikerImpl_Save
,
110 AntiMonikerImpl_GetSizeMax
,
111 AntiMonikerImpl_BindToObject
,
112 AntiMonikerImpl_BindToStorage
,
113 AntiMonikerImpl_Reduce
,
114 AntiMonikerImpl_ComposeWith
,
115 AntiMonikerImpl_Enum
,
116 AntiMonikerImpl_IsEqual
,
117 AntiMonikerImpl_Hash
,
118 AntiMonikerImpl_IsRunning
,
119 AntiMonikerImpl_GetTimeOfLastChange
,
120 AntiMonikerImpl_Inverse
,
121 AntiMonikerImpl_CommonPrefixWith
,
122 AntiMonikerImpl_RelativePathTo
,
123 AntiMonikerImpl_GetDisplayName
,
124 AntiMonikerImpl_ParseDisplayName
,
125 AntiMonikerImpl_IsSystemMoniker
128 /********************************************************************************/
129 /* Virtual function table for the IROTData class. */
130 static ICOM_VTABLE(IROTData
) VT_ROTDataImpl
=
132 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
133 AntiMonikerROTDataImpl_QueryInterface
,
134 AntiMonikerROTDataImpl_AddRef
,
135 AntiMonikerROTDataImpl_Release
,
136 AntiMonikerROTDataImpl_GetComparaisonData
139 /*******************************************************************************
140 * AntiMoniker_QueryInterface
141 *******************************************************************************/
142 HRESULT WINAPI
AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
144 ICOM_THIS(AntiMonikerImpl
,iface
);
146 TRACE("(%p,%p,%p)\n",This
,riid
,ppvObject
);
148 /* Perform a sanity check on the parameters.*/
149 if ( (This
==0) || (ppvObject
==0) )
152 /* Initialize the return parameter */
155 /* Compare the riid with the interface IDs implemented by this object.*/
156 if (IsEqualIID(&IID_IUnknown
, riid
) ||
157 IsEqualIID(&IID_IPersist
, riid
) ||
158 IsEqualIID(&IID_IPersistStream
, riid
) ||
159 IsEqualIID(&IID_IMoniker
, riid
)
162 else if (IsEqualIID(&IID_IROTData
, riid
))
163 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
165 /* Check that we obtained an interface.*/
167 return E_NOINTERFACE
;
169 /* Query Interface always increases the reference count by one when it is successful */
170 AntiMonikerImpl_AddRef(iface
);
175 /******************************************************************************
177 ******************************************************************************/
178 ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker
* iface
)
180 ICOM_THIS(AntiMonikerImpl
,iface
);
182 TRACE("(%p)\n",This
);
184 return ++(This
->ref
);
187 /******************************************************************************
188 * AntiMoniker_Release
189 ******************************************************************************/
190 ULONG WINAPI
AntiMonikerImpl_Release(IMoniker
* iface
)
192 ICOM_THIS(AntiMonikerImpl
,iface
);
194 TRACE("(%p)\n",This
);
198 /* destroy the object if there's no more reference on it */
201 AntiMonikerImpl_Destroy(This
);
208 /******************************************************************************
209 * AntiMoniker_GetClassID
210 ******************************************************************************/
211 HRESULT WINAPI
AntiMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
213 TRACE("(%p,%p),stub!\n",iface
,pClassID
);
218 *pClassID
= CLSID_AntiMoniker
;
223 /******************************************************************************
224 * AntiMoniker_IsDirty
225 ******************************************************************************/
226 HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker
* iface
)
228 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
229 method in the OLE-provided moniker interfaces always return S_FALSE because
230 their internal state never changes. */
232 TRACE("(%p)\n",iface
);
237 /******************************************************************************
239 ******************************************************************************/
240 HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
242 DWORD constant
=1,dwbuffer
;
245 /* data read by this function is only a DWORD constant (must be 1) ! */
246 res
=IStream_Read(pStm
,&dwbuffer
,sizeof(DWORD
),NULL
);
248 if (SUCCEEDED(res
)&& dwbuffer
!=constant
)
254 /******************************************************************************
256 ******************************************************************************/
257 HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker
* iface
,IStream
* pStm
,BOOL fClearDirty
)
262 /* data writen by this function is only a DWORD constant seted to 1 ! */
263 res
=IStream_Write(pStm
,&constant
,sizeof(constant
),NULL
);
268 /******************************************************************************
269 * AntiMoniker_GetSizeMax
270 ******************************************************************************/
271 HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker
* iface
,
272 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
274 TRACE("(%p,%p)\n",iface
,pcbSize
);
279 /* for more details see AntiMonikerImpl_Save coments */
281 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
282 /* more than the number of bytes used by AntiMoniker::Save function */
283 pcbSize
->s
.LowPart
= sizeof(DWORD
)+16;
285 pcbSize
->s
.HighPart
=0;
290 /******************************************************************************
291 * AntiMoniker_Construct (local function)
292 *******************************************************************************/
293 HRESULT WINAPI
AntiMonikerImpl_Construct(AntiMonikerImpl
* This
)
296 TRACE("(%p)\n",This
);
298 /* Initialize the virtual fgunction table. */
299 This
->lpvtbl1
= &VT_AntiMonikerImpl
;
300 This
->lpvtbl2
= &VT_ROTDataImpl
;
306 /******************************************************************************
307 * AntiMoniker_Destroy (local function)
308 *******************************************************************************/
309 HRESULT WINAPI
AntiMonikerImpl_Destroy(AntiMonikerImpl
* This
)
311 TRACE("(%p)\n",This
);
313 return HeapFree(GetProcessHeap(),0,This
);
316 /******************************************************************************
317 * AntiMoniker_BindToObject
318 ******************************************************************************/
319 HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker
* iface
,
325 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
329 /******************************************************************************
330 * AntiMoniker_BindToStorage
331 ******************************************************************************/
332 HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker
* iface
,
338 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
342 /******************************************************************************
344 ******************************************************************************/
345 HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker
* iface
,
347 DWORD dwReduceHowFar
,
348 IMoniker
** ppmkToLeft
,
349 IMoniker
** ppmkReduced
)
351 TRACE("(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
353 if (ppmkReduced
==NULL
)
356 AntiMonikerImpl_AddRef(iface
);
360 return MK_S_REDUCED_TO_SELF
;
362 /******************************************************************************
363 * AntiMoniker_ComposeWith
364 ******************************************************************************/
365 HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker
* iface
,
367 BOOL fOnlyIfNotGeneric
,
368 IMoniker
** ppmkComposite
)
371 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
373 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
378 if (fOnlyIfNotGeneric
)
379 return MK_E_NEEDGENERIC
;
381 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
384 /******************************************************************************
386 ******************************************************************************/
387 HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
389 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
391 if (ppenumMoniker
== NULL
)
394 *ppenumMoniker
= NULL
;
399 /******************************************************************************
400 * AntiMoniker_IsEqual
401 ******************************************************************************/
402 HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
406 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
408 if (pmkOtherMoniker
==NULL
)
411 IMoniker_IsSystemMoniker(pmkOtherMoniker
,&mkSys
);
413 if (mkSys
==MKSYS_ANTIMONIKER
)
419 /******************************************************************************
421 ******************************************************************************/
422 HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
432 /******************************************************************************
433 * AntiMoniker_IsRunning
434 ******************************************************************************/
435 HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker
* iface
,
438 IMoniker
* pmkNewlyRunning
)
440 IRunningObjectTable
* rot
;
443 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
448 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
453 res
= IRunningObjectTable_IsRunning(rot
,iface
);
455 IRunningObjectTable_Release(rot
);
460 /******************************************************************************
461 * AntiMoniker_GetTimeOfLastChange
462 ******************************************************************************/
463 HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
468 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pAntiTime
);
472 /******************************************************************************
473 * AntiMoniker_Inverse
474 ******************************************************************************/
475 HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
477 TRACE("(%p,%p)\n",iface
,ppmk
);
484 return MK_E_NOINVERSE
;
487 /******************************************************************************
488 * AntiMoniker_CommonPrefixWith
489 ******************************************************************************/
490 HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
494 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
496 if(mkSys
==MKSYS_ITEMMONIKER
){
498 IMoniker_AddRef(iface
);
502 IMoniker_AddRef(iface
);
507 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
510 /******************************************************************************
511 * AntiMoniker_RelativePathTo
512 ******************************************************************************/
513 HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
515 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
517 if (ppmkRelPath
==NULL
)
520 IMoniker_AddRef(pmOther
);
522 *ppmkRelPath
=pmOther
;
527 /******************************************************************************
528 * AntiMoniker_GetDisplayName
529 ******************************************************************************/
530 HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker
* iface
,
533 LPOLESTR
*ppszDisplayName
)
535 WCHAR back
[]={'\\','.','.',0};
537 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
539 if (ppszDisplayName
==NULL
)
542 if (pmkToLeft
!=NULL
){
543 FIXME("() pmkToLeft!=NULL not implemented \n");
547 *ppszDisplayName
=CoTaskMemAlloc(sizeof(back
));
549 if (*ppszDisplayName
==NULL
)
550 return E_OUTOFMEMORY
;
552 strcpyW(*ppszDisplayName
,back
);
557 /******************************************************************************
558 * AntiMoniker_ParseDisplayName
559 ******************************************************************************/
560 HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
,
563 LPOLESTR pszDisplayName
,
567 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pszDisplayName
,pchEaten
,ppmkOut
);
571 /******************************************************************************
572 * AntiMoniker_IsSystemMoniker
573 ******************************************************************************/
574 HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
576 TRACE("(%p,%p)\n",iface
,pwdMksys
);
581 (*pwdMksys
)=MKSYS_ANTIMONIKER
;
586 /*******************************************************************************
587 * AntiMonikerIROTData_QueryInterface
588 *******************************************************************************/
589 HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
592 ICOM_THIS_From_IROTData(IMoniker
, iface
);
594 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
596 return AntiMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
599 /***********************************************************************
600 * AntiMonikerIROTData_AddRef
602 ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
*iface
)
604 ICOM_THIS_From_IROTData(IMoniker
, iface
);
606 TRACE("(%p)\n",iface
);
608 return AntiMonikerImpl_AddRef(This
);
611 /***********************************************************************
612 * AntiMonikerIROTData_Release
614 ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
)
616 ICOM_THIS_From_IROTData(IMoniker
, iface
);
618 TRACE("(%p)\n",iface
);
620 return AntiMonikerImpl_Release(This
);
623 /******************************************************************************
624 * AntiMonikerIROTData_GetComparaisonData
625 ******************************************************************************/
626 HRESULT WINAPI
AntiMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,
635 /******************************************************************************
636 * CreateAntiMoniker [OLE32.51]
637 ******************************************************************************/
638 HRESULT WINAPI
CreateAntiMoniker(LPMONIKER
* ppmk
)
640 AntiMonikerImpl
* newAntiMoniker
= 0;
642 IID riid
=IID_IMoniker
;
644 TRACE("(%p)\n",ppmk
);
646 newAntiMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl
));
648 if (newAntiMoniker
== 0)
649 return STG_E_INSUFFICIENTMEMORY
;
651 hr
= AntiMonikerImpl_Construct(newAntiMoniker
);
655 HeapFree(GetProcessHeap(),0,newAntiMoniker
);
659 hr
= AntiMonikerImpl_QueryInterface((IMoniker
*)newAntiMoniker
,&riid
,(void**)ppmk
);