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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
38 /* AntiMoniker data structure */
39 typedef struct AntiMonikerImpl
{
41 const IMonikerVtbl
* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
43 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
44 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
46 const IROTDataVtbl
* lpvtbl2
; /* VTable relative to the IROTData interface.*/
48 LONG ref
; /* reference counter for this object */
50 IUnknown
*pMarshal
; /* custom marshaler */
53 static inline IMoniker
*impl_from_IROTData( IROTData
*iface
)
55 return (IMoniker
*)((char*)iface
- FIELD_OFFSET(AntiMonikerImpl
, lpvtbl2
));
59 /*******************************************************************************
60 * AntiMoniker_QueryInterface
61 *******************************************************************************/
63 AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
65 AntiMonikerImpl
*This
= (AntiMonikerImpl
*)iface
;
67 TRACE("(%p,%p,%p)\n",This
,riid
,ppvObject
);
69 /* Perform a sanity check on the parameters.*/
73 /* Initialize the return parameter */
76 /* Compare the riid with the interface IDs implemented by this object.*/
77 if (IsEqualIID(&IID_IUnknown
, riid
) ||
78 IsEqualIID(&IID_IPersist
, riid
) ||
79 IsEqualIID(&IID_IPersistStream
, riid
) ||
80 IsEqualIID(&IID_IMoniker
, riid
))
82 else if (IsEqualIID(&IID_IROTData
, riid
))
83 *ppvObject
= &This
->lpvtbl2
;
84 else if (IsEqualIID(&IID_IMarshal
, riid
))
88 hr
= MonikerMarshal_Create(iface
, &This
->pMarshal
);
91 return IUnknown_QueryInterface(This
->pMarshal
, riid
, ppvObject
);
94 /* Check that we obtained an interface.*/
98 /* always increase the reference count by one when it is successful */
99 IMoniker_AddRef(iface
);
104 /******************************************************************************
106 ******************************************************************************/
108 AntiMonikerImpl_AddRef(IMoniker
* iface
)
110 AntiMonikerImpl
*This
= (AntiMonikerImpl
*)iface
;
112 TRACE("(%p)\n",This
);
114 return InterlockedIncrement(&This
->ref
);
117 /******************************************************************************
118 * AntiMoniker_Release
119 ******************************************************************************/
121 AntiMonikerImpl_Release(IMoniker
* iface
)
123 AntiMonikerImpl
*This
= (AntiMonikerImpl
*)iface
;
126 TRACE("(%p)\n",This
);
128 ref
= InterlockedDecrement(&This
->ref
);
130 /* destroy the object if there's no more reference on it */
133 if (This
->pMarshal
) IUnknown_Release(This
->pMarshal
);
134 HeapFree(GetProcessHeap(),0,This
);
140 /******************************************************************************
141 * AntiMoniker_GetClassID
142 ******************************************************************************/
143 static HRESULT WINAPI
144 AntiMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
146 TRACE("(%p,%p)\n",iface
,pClassID
);
151 *pClassID
= CLSID_AntiMoniker
;
156 /******************************************************************************
157 * AntiMoniker_IsDirty
158 ******************************************************************************/
159 static HRESULT WINAPI
160 AntiMonikerImpl_IsDirty(IMoniker
* iface
)
162 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
163 method in the OLE-provided moniker interfaces always return S_FALSE because
164 their internal state never changes. */
166 TRACE("(%p)\n",iface
);
171 /******************************************************************************
173 ******************************************************************************/
174 static HRESULT WINAPI
175 AntiMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
177 DWORD constant
=1,dwbuffer
;
180 /* data read by this function is only a DWORD constant (must be 1) ! */
181 res
=IStream_Read(pStm
,&dwbuffer
,sizeof(DWORD
),NULL
);
183 if (SUCCEEDED(res
)&& dwbuffer
!=constant
)
189 /******************************************************************************
191 ******************************************************************************/
192 static HRESULT WINAPI
193 AntiMonikerImpl_Save(IMoniker
* iface
,IStream
* pStm
,BOOL fClearDirty
)
195 static const DWORD constant
= 1;
196 /* data written by this function is only a DWORD constant set to 1 ! */
197 return IStream_Write(pStm
,&constant
,sizeof(constant
),NULL
);
200 /******************************************************************************
201 * AntiMoniker_GetSizeMax
204 * pcbSize [out] Pointer to size of stream needed to save object
205 ******************************************************************************/
206 static HRESULT WINAPI
207 AntiMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
)
209 TRACE("(%p,%p)\n",iface
,pcbSize
);
214 /* for more details see AntiMonikerImpl_Save comments */
217 * Normally the sizemax must be sizeof DWORD, but
218 * I tested this function it usually return 16 bytes
219 * more than the number of bytes used by AntiMoniker::Save function
221 pcbSize
->u
.LowPart
= sizeof(DWORD
)+16;
223 pcbSize
->u
.HighPart
=0;
228 /******************************************************************************
229 * AntiMoniker_BindToObject
230 ******************************************************************************/
231 static HRESULT WINAPI
232 AntiMonikerImpl_BindToObject(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
,
233 REFIID riid
, VOID
** ppvResult
)
235 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
239 /******************************************************************************
240 * AntiMoniker_BindToStorage
241 ******************************************************************************/
242 static HRESULT WINAPI
243 AntiMonikerImpl_BindToStorage(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
,
244 REFIID riid
, VOID
** ppvResult
)
246 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
250 /******************************************************************************
252 ******************************************************************************/
253 static HRESULT WINAPI
254 AntiMonikerImpl_Reduce(IMoniker
* iface
, IBindCtx
* pbc
, DWORD dwReduceHowFar
,
255 IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
)
257 TRACE("(%p,%p,%d,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
259 if (ppmkReduced
==NULL
)
262 AntiMonikerImpl_AddRef(iface
);
266 return MK_S_REDUCED_TO_SELF
;
268 /******************************************************************************
269 * AntiMoniker_ComposeWith
270 ******************************************************************************/
271 static HRESULT WINAPI
272 AntiMonikerImpl_ComposeWith(IMoniker
* iface
, IMoniker
* pmkRight
,
273 BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
)
276 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
278 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
283 if (fOnlyIfNotGeneric
)
284 return MK_E_NEEDGENERIC
;
286 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
289 /******************************************************************************
291 ******************************************************************************/
292 static HRESULT WINAPI
293 AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
295 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
297 if (ppenumMoniker
== NULL
)
300 *ppenumMoniker
= NULL
;
305 /******************************************************************************
306 * AntiMoniker_IsEqual
307 ******************************************************************************/
308 static HRESULT WINAPI
309 AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
313 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
315 if (pmkOtherMoniker
==NULL
)
318 IMoniker_IsSystemMoniker(pmkOtherMoniker
,&mkSys
);
320 if (mkSys
==MKSYS_ANTIMONIKER
)
326 /******************************************************************************
328 ******************************************************************************/
329 static HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
334 *pdwHash
= 0x80000001;
339 /******************************************************************************
340 * AntiMoniker_IsRunning
341 ******************************************************************************/
342 static HRESULT WINAPI
343 AntiMonikerImpl_IsRunning(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
,
344 IMoniker
* pmkNewlyRunning
)
346 IRunningObjectTable
* rot
;
349 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
354 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
359 res
= IRunningObjectTable_IsRunning(rot
,iface
);
361 IRunningObjectTable_Release(rot
);
366 /******************************************************************************
367 * AntiMoniker_GetTimeOfLastChange
368 ******************************************************************************/
369 static HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
374 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pAntiTime
);
378 /******************************************************************************
379 * AntiMoniker_Inverse
380 ******************************************************************************/
381 static HRESULT WINAPI
382 AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
384 TRACE("(%p,%p)\n",iface
,ppmk
);
391 return MK_E_NOINVERSE
;
394 /******************************************************************************
395 * AntiMoniker_CommonPrefixWith
396 ******************************************************************************/
397 static HRESULT WINAPI
398 AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
402 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
404 if(mkSys
==MKSYS_ANTIMONIKER
){
406 IMoniker_AddRef(iface
);
410 IMoniker_AddRef(iface
);
415 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
418 /******************************************************************************
419 * AntiMoniker_RelativePathTo
420 ******************************************************************************/
421 static HRESULT WINAPI
422 AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
424 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
426 if (ppmkRelPath
==NULL
)
429 IMoniker_AddRef(pmOther
);
431 *ppmkRelPath
=pmOther
;
436 /******************************************************************************
437 * AntiMoniker_GetDisplayName
438 ******************************************************************************/
439 static HRESULT WINAPI
440 AntiMonikerImpl_GetDisplayName(IMoniker
* iface
, IBindCtx
* pbc
,
441 IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
)
443 static const WCHAR back
[]={'\\','.','.',0};
445 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
447 if (ppszDisplayName
==NULL
)
450 if (pmkToLeft
!=NULL
){
451 FIXME("() pmkToLeft!=NULL not implemented\n");
455 *ppszDisplayName
=CoTaskMemAlloc(sizeof(back
));
457 if (*ppszDisplayName
==NULL
)
458 return E_OUTOFMEMORY
;
460 lstrcpyW(*ppszDisplayName
,back
);
465 /******************************************************************************
466 * AntiMoniker_ParseDisplayName
467 ******************************************************************************/
468 static HRESULT WINAPI
469 AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
, IBindCtx
* pbc
,
470 IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
,
471 ULONG
* pchEaten
, IMoniker
** ppmkOut
)
473 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pszDisplayName
,pchEaten
,ppmkOut
);
477 /******************************************************************************
478 * AntiMoniker_IsSystemMoniker
479 ******************************************************************************/
480 static HRESULT WINAPI
481 AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
483 TRACE("(%p,%p)\n",iface
,pwdMksys
);
488 (*pwdMksys
)=MKSYS_ANTIMONIKER
;
493 /*******************************************************************************
494 * AntiMonikerIROTData_QueryInterface
495 *******************************************************************************/
496 static HRESULT WINAPI
497 AntiMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
499 IMoniker
*This
= impl_from_IROTData(iface
);
501 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
503 return AntiMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
506 /***********************************************************************
507 * AntiMonikerIROTData_AddRef
509 static ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
*iface
)
511 IMoniker
*This
= impl_from_IROTData(iface
);
513 TRACE("(%p)\n",iface
);
515 return AntiMonikerImpl_AddRef(This
);
518 /***********************************************************************
519 * AntiMonikerIROTData_Release
521 static ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
)
523 IMoniker
*This
= impl_from_IROTData(iface
);
525 TRACE("(%p)\n",iface
);
527 return AntiMonikerImpl_Release(This
);
530 /******************************************************************************
531 * AntiMonikerIROTData_GetComparisonData
532 ******************************************************************************/
533 static HRESULT WINAPI
534 AntiMonikerROTDataImpl_GetComparisonData(IROTData
* iface
, BYTE
* pbData
,
535 ULONG cbMax
, ULONG
* pcbData
)
539 TRACE("(%p, %u, %p)\n", pbData
, cbMax
, pcbData
);
541 *pcbData
= sizeof(CLSID
) + sizeof(DWORD
);
542 if (cbMax
< *pcbData
)
543 return E_OUTOFMEMORY
;
545 memcpy(pbData
, &CLSID_AntiMoniker
, sizeof(CLSID
));
546 memcpy(pbData
+sizeof(CLSID
), &constant
, sizeof(DWORD
));
551 /********************************************************************************/
552 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
553 /* IPersistStream and IMoniker functions. */
554 static const IMonikerVtbl VT_AntiMonikerImpl
=
556 AntiMonikerImpl_QueryInterface
,
557 AntiMonikerImpl_AddRef
,
558 AntiMonikerImpl_Release
,
559 AntiMonikerImpl_GetClassID
,
560 AntiMonikerImpl_IsDirty
,
561 AntiMonikerImpl_Load
,
562 AntiMonikerImpl_Save
,
563 AntiMonikerImpl_GetSizeMax
,
564 AntiMonikerImpl_BindToObject
,
565 AntiMonikerImpl_BindToStorage
,
566 AntiMonikerImpl_Reduce
,
567 AntiMonikerImpl_ComposeWith
,
568 AntiMonikerImpl_Enum
,
569 AntiMonikerImpl_IsEqual
,
570 AntiMonikerImpl_Hash
,
571 AntiMonikerImpl_IsRunning
,
572 AntiMonikerImpl_GetTimeOfLastChange
,
573 AntiMonikerImpl_Inverse
,
574 AntiMonikerImpl_CommonPrefixWith
,
575 AntiMonikerImpl_RelativePathTo
,
576 AntiMonikerImpl_GetDisplayName
,
577 AntiMonikerImpl_ParseDisplayName
,
578 AntiMonikerImpl_IsSystemMoniker
581 /********************************************************************************/
582 /* Virtual function table for the IROTData class. */
583 static const IROTDataVtbl VT_ROTDataImpl
=
585 AntiMonikerROTDataImpl_QueryInterface
,
586 AntiMonikerROTDataImpl_AddRef
,
587 AntiMonikerROTDataImpl_Release
,
588 AntiMonikerROTDataImpl_GetComparisonData
591 /******************************************************************************
592 * AntiMoniker_Construct (local function)
593 *******************************************************************************/
594 static HRESULT
AntiMonikerImpl_Construct(AntiMonikerImpl
* This
)
597 TRACE("(%p)\n",This
);
599 /* Initialize the virtual function table. */
600 This
->lpvtbl1
= &VT_AntiMonikerImpl
;
601 This
->lpvtbl2
= &VT_ROTDataImpl
;
603 This
->pMarshal
= NULL
;
608 /******************************************************************************
609 * CreateAntiMoniker [OLE32.@]
610 ******************************************************************************/
611 HRESULT WINAPI
CreateAntiMoniker(LPMONIKER
* ppmk
)
613 AntiMonikerImpl
* newAntiMoniker
;
616 TRACE("(%p)\n",ppmk
);
618 newAntiMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl
));
620 if (newAntiMoniker
== 0)
621 return STG_E_INSUFFICIENTMEMORY
;
623 hr
= AntiMonikerImpl_Construct(newAntiMoniker
);
626 HeapFree(GetProcessHeap(),0,newAntiMoniker
);
630 return AntiMonikerImpl_QueryInterface((IMoniker
*)newAntiMoniker
,&IID_IMoniker
,(void**)ppmk
);
633 static HRESULT WINAPI
AntiMonikerCF_QueryInterface(LPCLASSFACTORY iface
,
634 REFIID riid
, LPVOID
*ppv
)
637 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
))
640 IUnknown_AddRef(iface
);
643 return E_NOINTERFACE
;
646 static ULONG WINAPI
AntiMonikerCF_AddRef(LPCLASSFACTORY iface
)
648 return 2; /* non-heap based object */
651 static ULONG WINAPI
AntiMonikerCF_Release(LPCLASSFACTORY iface
)
653 return 1; /* non-heap based object */
656 static HRESULT WINAPI
AntiMonikerCF_CreateInstance(LPCLASSFACTORY iface
,
657 LPUNKNOWN pUnk
, REFIID riid
, LPVOID
*ppv
)
662 TRACE("(%p, %s, %p)\n", pUnk
, debugstr_guid(riid
), ppv
);
667 return CLASS_E_NOAGGREGATION
;
669 hr
= CreateAntiMoniker(&pMoniker
);
673 hr
= IMoniker_QueryInterface(pMoniker
, riid
, ppv
);
676 IMoniker_Release(pMoniker
);
681 static HRESULT WINAPI
AntiMonikerCF_LockServer(LPCLASSFACTORY iface
, BOOL fLock
)
683 FIXME("(%d), stub!\n",fLock
);
687 static const IClassFactoryVtbl AntiMonikerCFVtbl
=
689 AntiMonikerCF_QueryInterface
,
690 AntiMonikerCF_AddRef
,
691 AntiMonikerCF_Release
,
692 AntiMonikerCF_CreateInstance
,
693 AntiMonikerCF_LockServer
695 static const IClassFactoryVtbl
*AntiMonikerCF
= &AntiMonikerCFVtbl
;
697 HRESULT
AntiMonikerCF_Create(REFIID riid
, LPVOID
*ppv
)
699 return IClassFactory_QueryInterface((IClassFactory
*)&AntiMonikerCF
, riid
, ppv
);