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.*/
70 if ( (This==0) || (ppvObject==0) )
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 = (IROTData*)&(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)
198 /* data written by this function is only a DWORD constant set to 1 ! */
199 res=IStream_Write(pStm,&constant,sizeof(constant),NULL);
204 /******************************************************************************
205 * AntiMoniker_GetSizeMax
208 * pcbSize [out] Pointer to size of stream needed to save object
209 ******************************************************************************/
210 static HRESULT WINAPI
211 AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize)
213 TRACE("(%p,%p)\n",iface,pcbSize);
218 /* for more details see AntiMonikerImpl_Save comments */
221 * Normally the sizemax must be sizeof DWORD, but
222 * I tested this function it usually return 16 bytes
223 * more than the number of bytes used by AntiMoniker::Save function
225 pcbSize->u.LowPart = sizeof(DWORD)+16;
227 pcbSize->u.HighPart=0;
232 /******************************************************************************
233 * AntiMoniker_BindToObject
234 ******************************************************************************/
235 static HRESULT WINAPI
236 AntiMonikerImpl_BindToObject(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
237 REFIID riid, VOID** ppvResult)
239 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
243 /******************************************************************************
244 * AntiMoniker_BindToStorage
245 ******************************************************************************/
246 static HRESULT WINAPI
247 AntiMonikerImpl_BindToStorage(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
248 REFIID riid, VOID** ppvResult)
250 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
254 /******************************************************************************
256 ******************************************************************************/
257 static HRESULT WINAPI
258 AntiMonikerImpl_Reduce(IMoniker* iface, IBindCtx* pbc, DWORD dwReduceHowFar,
259 IMoniker** ppmkToLeft, IMoniker** ppmkReduced)
261 TRACE("(%p,%p,%d,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
263 if (ppmkReduced==NULL)
266 AntiMonikerImpl_AddRef(iface);
270 return MK_S_REDUCED_TO_SELF;
272 /******************************************************************************
273 * AntiMoniker_ComposeWith
274 ******************************************************************************/
275 static HRESULT WINAPI
276 AntiMonikerImpl_ComposeWith(IMoniker* iface, IMoniker* pmkRight,
277 BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite)
280 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
282 if ((ppmkComposite==NULL)||(pmkRight==NULL))
287 if (fOnlyIfNotGeneric)
288 return MK_E_NEEDGENERIC;
290 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
293 /******************************************************************************
295 ******************************************************************************/
296 static HRESULT WINAPI
297 AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
299 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
301 if (ppenumMoniker == NULL)
304 *ppenumMoniker = NULL;
309 /******************************************************************************
310 * AntiMoniker_IsEqual
311 ******************************************************************************/
312 static HRESULT WINAPI
313 AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
317 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
319 if (pmkOtherMoniker==NULL)
322 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
324 if (mkSys==MKSYS_ANTIMONIKER)
330 /******************************************************************************
332 ******************************************************************************/
333 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
338 *pdwHash = 0x80000001;
343 /******************************************************************************
344 * AntiMoniker_IsRunning
345 ******************************************************************************/
346 static HRESULT WINAPI
347 AntiMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
348 IMoniker* pmkNewlyRunning)
350 IRunningObjectTable* rot;
353 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
358 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
363 res = IRunningObjectTable_IsRunning(rot,iface);
365 IRunningObjectTable_Release(rot);
370 /******************************************************************************
371 * AntiMoniker_GetTimeOfLastChange
372 ******************************************************************************/
373 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
378 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
382 /******************************************************************************
383 * AntiMoniker_Inverse
384 ******************************************************************************/
385 static HRESULT WINAPI
386 AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
388 TRACE("(%p,%p)\n",iface,ppmk);
395 return MK_E_NOINVERSE;
398 /******************************************************************************
399 * AntiMoniker_CommonPrefixWith
400 ******************************************************************************/
401 static HRESULT WINAPI
402 AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
406 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
408 if(mkSys==MKSYS_ANTIMONIKER){
410 IMoniker_AddRef(iface);
414 IMoniker_AddRef(iface);
419 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
422 /******************************************************************************
423 * AntiMoniker_RelativePathTo
424 ******************************************************************************/
425 static HRESULT WINAPI
426 AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
428 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
430 if (ppmkRelPath==NULL)
433 IMoniker_AddRef(pmOther);
435 *ppmkRelPath=pmOther;
440 /******************************************************************************
441 * AntiMoniker_GetDisplayName
442 ******************************************************************************/
443 static HRESULT WINAPI
444 AntiMonikerImpl_GetDisplayName(IMoniker* iface, IBindCtx* pbc,
445 IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName)
447 static const WCHAR back[]={'\\','.','.',0};
449 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
451 if (ppszDisplayName==NULL)
454 if (pmkToLeft!=NULL){
455 FIXME("() pmkToLeft!=NULL not implemented\n");
459 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
461 if (*ppszDisplayName==NULL)
462 return E_OUTOFMEMORY;
464 lstrcpyW(*ppszDisplayName,back);
469 /******************************************************************************
470 * AntiMoniker_ParseDisplayName
471 ******************************************************************************/
472 static HRESULT WINAPI
473 AntiMonikerImpl_ParseDisplayName(IMoniker* iface, IBindCtx* pbc,
474 IMoniker* pmkToLeft, LPOLESTR pszDisplayName,
475 ULONG* pchEaten, IMoniker** ppmkOut)
477 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
481 /******************************************************************************
482 * AntiMoniker_IsSystemMoniker
483 ******************************************************************************/
484 static HRESULT WINAPI
485 AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
487 TRACE("(%p,%p)\n",iface,pwdMksys);
492 (*pwdMksys)=MKSYS_ANTIMONIKER;
497 /*******************************************************************************
498 * AntiMonikerIROTData_QueryInterface
499 *******************************************************************************/
500 static HRESULT WINAPI
501 AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
503 IMoniker *This = impl_from_IROTData(iface);
505 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
507 return AntiMonikerImpl_QueryInterface(This, riid, ppvObject);
510 /***********************************************************************
511 * AntiMonikerIROTData_AddRef
513 static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
515 IMoniker *This = impl_from_IROTData(iface);
517 TRACE("(%p)\n",iface);
519 return AntiMonikerImpl_AddRef(This);
522 /***********************************************************************
523 * AntiMonikerIROTData_Release
525 static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
527 IMoniker *This = impl_from_IROTData(iface);
529 TRACE("(%p)\n",iface);
531 return AntiMonikerImpl_Release(This);
534 /******************************************************************************
535 * AntiMonikerIROTData_GetComparisonData
536 ******************************************************************************/
537 static HRESULT WINAPI
538 AntiMonikerROTDataImpl_GetComparisonData(IROTData* iface, BYTE* pbData,
539 ULONG cbMax, ULONG* pcbData)
543 TRACE("(%p, %u, %p)\n", pbData, cbMax, pcbData);
545 *pcbData = sizeof(CLSID) + sizeof(DWORD);
546 if (cbMax < *pcbData)
547 return E_OUTOFMEMORY;
549 memcpy(pbData, &CLSID_AntiMoniker, sizeof(CLSID));
550 memcpy(pbData+sizeof(CLSID), &constant, sizeof(DWORD));
555 /********************************************************************************/
556 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
557 /* IPersistStream and IMoniker functions. */
558 static const IMonikerVtbl VT_AntiMonikerImpl =
560 AntiMonikerImpl_QueryInterface,
561 AntiMonikerImpl_AddRef,
562 AntiMonikerImpl_Release,
563 AntiMonikerImpl_GetClassID,
564 AntiMonikerImpl_IsDirty,
565 AntiMonikerImpl_Load,
566 AntiMonikerImpl_Save,
567 AntiMonikerImpl_GetSizeMax,
568 AntiMonikerImpl_BindToObject,
569 AntiMonikerImpl_BindToStorage,
570 AntiMonikerImpl_Reduce,
571 AntiMonikerImpl_ComposeWith,
572 AntiMonikerImpl_Enum,
573 AntiMonikerImpl_IsEqual,
574 AntiMonikerImpl_Hash,
575 AntiMonikerImpl_IsRunning,
576 AntiMonikerImpl_GetTimeOfLastChange,
577 AntiMonikerImpl_Inverse,
578 AntiMonikerImpl_CommonPrefixWith,
579 AntiMonikerImpl_RelativePathTo,
580 AntiMonikerImpl_GetDisplayName,
581 AntiMonikerImpl_ParseDisplayName,
582 AntiMonikerImpl_IsSystemMoniker
585 /********************************************************************************/
586 /* Virtual function table for the IROTData class. */
587 static const IROTDataVtbl VT_ROTDataImpl =
589 AntiMonikerROTDataImpl_QueryInterface,
590 AntiMonikerROTDataImpl_AddRef,
591 AntiMonikerROTDataImpl_Release,
592 AntiMonikerROTDataImpl_GetComparisonData
595 /******************************************************************************
596 * AntiMoniker_Construct (local function)
597 *******************************************************************************/
598 static HRESULT AntiMonikerImpl_Construct(AntiMonikerImpl* This)
601 TRACE("(%p)\n",This);
603 /* Initialize the virtual function table. */
604 This->lpvtbl1 = &VT_AntiMonikerImpl;
605 This->lpvtbl2 = &VT_ROTDataImpl;
607 This->pMarshal = NULL;
612 /******************************************************************************
613 * CreateAntiMoniker [OLE32.@]
614 ******************************************************************************/
615 HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
617 AntiMonikerImpl* newAntiMoniker = 0;
619 IID riid=IID_IMoniker;
621 TRACE("(%p)\n",ppmk);
623 newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));
625 if (newAntiMoniker == 0)
626 return STG_E_INSUFFICIENTMEMORY;
628 hr = AntiMonikerImpl_Construct(newAntiMoniker);
631 HeapFree(GetProcessHeap(),0,newAntiMoniker);
635 hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk);
640 static HRESULT WINAPI AntiMonikerCF_QueryInterface(LPCLASSFACTORY iface,
641 REFIID riid, LPVOID *ppv)
644 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
647 IUnknown_AddRef(iface);
650 return E_NOINTERFACE;
653 static ULONG WINAPI AntiMonikerCF_AddRef(LPCLASSFACTORY iface)
655 return 2; /* non-heap based object */
658 static ULONG WINAPI AntiMonikerCF_Release(LPCLASSFACTORY iface)
660 return 1; /* non-heap based object */
663 static HRESULT WINAPI AntiMonikerCF_CreateInstance(LPCLASSFACTORY iface,
664 LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
669 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);
674 return CLASS_E_NOAGGREGATION;
676 hr = CreateAntiMoniker(&pMoniker);
680 hr = IMoniker_QueryInterface(pMoniker, riid, ppv);
683 IMoniker_Release(pMoniker);
688 static HRESULT WINAPI AntiMonikerCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
690 FIXME("(%d), stub!\n",fLock);
694 static const IClassFactoryVtbl AntiMonikerCFVtbl =
696 AntiMonikerCF_QueryInterface,
697 AntiMonikerCF_AddRef,
698 AntiMonikerCF_Release,
699 AntiMonikerCF_CreateInstance,
700 AntiMonikerCF_LockServer
702 static const IClassFactoryVtbl *AntiMonikerCF = &AntiMonikerCFVtbl;
704 HRESULT AntiMonikerCF_Create(REFIID riid, LPVOID *ppv)
706 return IClassFactory_QueryInterface((IClassFactory *)&AntiMonikerCF, riid, ppv);