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 ***************************************************************************************/
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ole);
38 const CLSID CLSID_AntiMoniker = {
39 0x305, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
42 /* AntiMoniker data structure */
43 typedef struct AntiMonikerImpl{
45 const IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/
47 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
48 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
50 const IROTDataVtbl* lpvtbl2; /* VTable relative to the IROTData interface.*/
52 LONG ref; /* reference counter for this object */
56 static inline IMoniker *impl_from_IROTData( IROTData *iface )
58 return (IMoniker *)((char*)iface - FIELD_OFFSET(AntiMonikerImpl, lpvtbl2));
62 /*******************************************************************************
63 * AntiMoniker_QueryInterface
64 *******************************************************************************/
66 AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
68 AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
70 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
72 /* Perform a sanity check on the parameters.*/
73 if ( (This==0) || (ppvObject==0) )
76 /* Initialize the return parameter */
79 /* Compare the riid with the interface IDs implemented by this object.*/
80 if (IsEqualIID(&IID_IUnknown, riid) ||
81 IsEqualIID(&IID_IPersist, riid) ||
82 IsEqualIID(&IID_IPersistStream, riid) ||
83 IsEqualIID(&IID_IMoniker, riid))
85 else if (IsEqualIID(&IID_IROTData, riid))
86 *ppvObject = (IROTData*)&(This->lpvtbl2);
88 /* Check that we obtained an interface.*/
92 /* always increase the reference count by one when it is successful */
93 IMoniker_AddRef(iface);
98 /******************************************************************************
100 ******************************************************************************/
102 AntiMonikerImpl_AddRef(IMoniker* iface)
104 AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
106 TRACE("(%p)\n",This);
108 return InterlockedIncrement(&This->ref);
111 /******************************************************************************
112 * AntiMoniker_Release
113 ******************************************************************************/
115 AntiMonikerImpl_Release(IMoniker* iface)
117 AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
120 TRACE("(%p)\n",This);
122 ref = InterlockedDecrement(&This->ref);
124 /* destroy the object if there's no more reference on it */
125 if (ref == 0) HeapFree(GetProcessHeap(),0,This);
130 /******************************************************************************
131 * AntiMoniker_GetClassID
132 ******************************************************************************/
133 static HRESULT WINAPI
134 AntiMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
136 TRACE("(%p,%p)\n",iface,pClassID);
141 *pClassID = CLSID_AntiMoniker;
146 /******************************************************************************
147 * AntiMoniker_IsDirty
148 ******************************************************************************/
149 static HRESULT WINAPI
150 AntiMonikerImpl_IsDirty(IMoniker* iface)
152 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
153 method in the OLE-provided moniker interfaces always return S_FALSE because
154 their internal state never changes. */
156 TRACE("(%p)\n",iface);
161 /******************************************************************************
163 ******************************************************************************/
164 static HRESULT WINAPI
165 AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
167 DWORD constant=1,dwbuffer;
170 /* data read by this function is only a DWORD constant (must be 1) ! */
171 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),NULL);
173 if (SUCCEEDED(res)&& dwbuffer!=constant)
179 /******************************************************************************
181 ******************************************************************************/
182 static HRESULT WINAPI
183 AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
188 /* data written by this function is only a DWORD constant set to 1 ! */
189 res=IStream_Write(pStm,&constant,sizeof(constant),NULL);
194 /******************************************************************************
195 * AntiMoniker_GetSizeMax
198 * pcbSize [out] Pointer to size of stream needed to save object
199 ******************************************************************************/
200 static HRESULT WINAPI
201 AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize)
203 TRACE("(%p,%p)\n",iface,pcbSize);
208 /* for more details see AntiMonikerImpl_Save coments */
211 * Normally the sizemax must be sizeof DWORD, but
212 * I tested this function it usually return 16 bytes
213 * more than the number of bytes used by AntiMoniker::Save function
215 pcbSize->u.LowPart = sizeof(DWORD)+16;
217 pcbSize->u.HighPart=0;
222 /******************************************************************************
223 * AntiMoniker_BindToObject
224 ******************************************************************************/
225 static HRESULT WINAPI
226 AntiMonikerImpl_BindToObject(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
227 REFIID riid, VOID** ppvResult)
229 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
233 /******************************************************************************
234 * AntiMoniker_BindToStorage
235 ******************************************************************************/
236 static HRESULT WINAPI
237 AntiMonikerImpl_BindToStorage(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
238 REFIID riid, VOID** ppvResult)
240 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
244 /******************************************************************************
246 ******************************************************************************/
247 static HRESULT WINAPI
248 AntiMonikerImpl_Reduce(IMoniker* iface, IBindCtx* pbc, DWORD dwReduceHowFar,
249 IMoniker** ppmkToLeft, IMoniker** ppmkReduced)
251 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
253 if (ppmkReduced==NULL)
256 AntiMonikerImpl_AddRef(iface);
260 return MK_S_REDUCED_TO_SELF;
262 /******************************************************************************
263 * AntiMoniker_ComposeWith
264 ******************************************************************************/
265 static HRESULT WINAPI
266 AntiMonikerImpl_ComposeWith(IMoniker* iface, IMoniker* pmkRight,
267 BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite)
270 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
272 if ((ppmkComposite==NULL)||(pmkRight==NULL))
277 if (fOnlyIfNotGeneric)
278 return MK_E_NEEDGENERIC;
280 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
283 /******************************************************************************
285 ******************************************************************************/
286 static HRESULT WINAPI
287 AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
289 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
291 if (ppenumMoniker == NULL)
294 *ppenumMoniker = NULL;
299 /******************************************************************************
300 * AntiMoniker_IsEqual
301 ******************************************************************************/
302 static HRESULT WINAPI
303 AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
307 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
309 if (pmkOtherMoniker==NULL)
312 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
314 if (mkSys==MKSYS_ANTIMONIKER)
320 /******************************************************************************
322 ******************************************************************************/
323 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
333 /******************************************************************************
334 * AntiMoniker_IsRunning
335 ******************************************************************************/
336 static HRESULT WINAPI
337 AntiMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
338 IMoniker* pmkNewlyRunning)
340 IRunningObjectTable* rot;
343 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
348 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
353 res = IRunningObjectTable_IsRunning(rot,iface);
355 IRunningObjectTable_Release(rot);
360 /******************************************************************************
361 * AntiMoniker_GetTimeOfLastChange
362 ******************************************************************************/
363 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
368 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
372 /******************************************************************************
373 * AntiMoniker_Inverse
374 ******************************************************************************/
375 static HRESULT WINAPI
376 AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
378 TRACE("(%p,%p)\n",iface,ppmk);
385 return MK_E_NOINVERSE;
388 /******************************************************************************
389 * AntiMoniker_CommonPrefixWith
390 ******************************************************************************/
391 static HRESULT WINAPI
392 AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
396 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
398 if(mkSys==MKSYS_ITEMMONIKER){
400 IMoniker_AddRef(iface);
404 IMoniker_AddRef(iface);
409 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
412 /******************************************************************************
413 * AntiMoniker_RelativePathTo
414 ******************************************************************************/
415 static HRESULT WINAPI
416 AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
418 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
420 if (ppmkRelPath==NULL)
423 IMoniker_AddRef(pmOther);
425 *ppmkRelPath=pmOther;
430 /******************************************************************************
431 * AntiMoniker_GetDisplayName
432 ******************************************************************************/
433 static HRESULT WINAPI
434 AntiMonikerImpl_GetDisplayName(IMoniker* iface, IBindCtx* pbc,
435 IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName)
437 static const WCHAR back[]={'\\','.','.',0};
439 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
441 if (ppszDisplayName==NULL)
444 if (pmkToLeft!=NULL){
445 FIXME("() pmkToLeft!=NULL not implemented\n");
449 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
451 if (*ppszDisplayName==NULL)
452 return E_OUTOFMEMORY;
454 lstrcpyW(*ppszDisplayName,back);
459 /******************************************************************************
460 * AntiMoniker_ParseDisplayName
461 ******************************************************************************/
462 static HRESULT WINAPI
463 AntiMonikerImpl_ParseDisplayName(IMoniker* iface, IBindCtx* pbc,
464 IMoniker* pmkToLeft, LPOLESTR pszDisplayName,
465 ULONG* pchEaten, IMoniker** ppmkOut)
467 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
471 /******************************************************************************
472 * AntiMoniker_IsSystemMoniker
473 ******************************************************************************/
474 static HRESULT WINAPI
475 AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
477 TRACE("(%p,%p)\n",iface,pwdMksys);
482 (*pwdMksys)=MKSYS_ANTIMONIKER;
487 /*******************************************************************************
488 * AntiMonikerIROTData_QueryInterface
489 *******************************************************************************/
490 static HRESULT WINAPI
491 AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
493 IMoniker *This = impl_from_IROTData(iface);
495 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
497 return AntiMonikerImpl_QueryInterface(This, riid, ppvObject);
500 /***********************************************************************
501 * AntiMonikerIROTData_AddRef
503 static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
505 IMoniker *This = impl_from_IROTData(iface);
507 TRACE("(%p)\n",iface);
509 return AntiMonikerImpl_AddRef(This);
512 /***********************************************************************
513 * AntiMonikerIROTData_Release
515 static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
517 IMoniker *This = impl_from_IROTData(iface);
519 TRACE("(%p)\n",iface);
521 return AntiMonikerImpl_Release(This);
524 /******************************************************************************
525 * AntiMonikerIROTData_GetComparaisonData
526 ******************************************************************************/
527 static HRESULT WINAPI
528 AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface, BYTE* pbData,
529 ULONG cbMax, ULONG* pcbData)
535 /********************************************************************************/
536 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
537 /* IPersistStream and IMoniker functions. */
538 static const IMonikerVtbl VT_AntiMonikerImpl =
540 AntiMonikerImpl_QueryInterface,
541 AntiMonikerImpl_AddRef,
542 AntiMonikerImpl_Release,
543 AntiMonikerImpl_GetClassID,
544 AntiMonikerImpl_IsDirty,
545 AntiMonikerImpl_Load,
546 AntiMonikerImpl_Save,
547 AntiMonikerImpl_GetSizeMax,
548 AntiMonikerImpl_BindToObject,
549 AntiMonikerImpl_BindToStorage,
550 AntiMonikerImpl_Reduce,
551 AntiMonikerImpl_ComposeWith,
552 AntiMonikerImpl_Enum,
553 AntiMonikerImpl_IsEqual,
554 AntiMonikerImpl_Hash,
555 AntiMonikerImpl_IsRunning,
556 AntiMonikerImpl_GetTimeOfLastChange,
557 AntiMonikerImpl_Inverse,
558 AntiMonikerImpl_CommonPrefixWith,
559 AntiMonikerImpl_RelativePathTo,
560 AntiMonikerImpl_GetDisplayName,
561 AntiMonikerImpl_ParseDisplayName,
562 AntiMonikerImpl_IsSystemMoniker
565 /********************************************************************************/
566 /* Virtual function table for the IROTData class. */
567 static const IROTDataVtbl VT_ROTDataImpl =
569 AntiMonikerROTDataImpl_QueryInterface,
570 AntiMonikerROTDataImpl_AddRef,
571 AntiMonikerROTDataImpl_Release,
572 AntiMonikerROTDataImpl_GetComparaisonData
575 /******************************************************************************
576 * AntiMoniker_Construct (local function)
577 *******************************************************************************/
578 static HRESULT AntiMonikerImpl_Construct(AntiMonikerImpl* This)
581 TRACE("(%p)\n",This);
583 /* Initialize the virtual fgunction table. */
584 This->lpvtbl1 = &VT_AntiMonikerImpl;
585 This->lpvtbl2 = &VT_ROTDataImpl;
591 /******************************************************************************
592 * CreateAntiMoniker [OLE32.@]
593 ******************************************************************************/
594 HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
596 AntiMonikerImpl* newAntiMoniker = 0;
598 IID riid=IID_IMoniker;
600 TRACE("(%p)\n",ppmk);
602 newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));
604 if (newAntiMoniker == 0)
605 return STG_E_INSUFFICIENTMEMORY;
607 hr = AntiMonikerImpl_Construct(newAntiMoniker);
610 HeapFree(GetProcessHeap(),0,newAntiMoniker);
614 hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk);