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 ***************************************************************************************/
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
28 #include "wine/unicode.h"
30 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
35 const CLSID CLSID_AntiMoniker
= {
36 0x305, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
39 /* AntiMoniker data structure */
40 typedef struct AntiMonikerImpl
{
42 ICOM_VTABLE(IMoniker
)* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
44 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
45 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
47 ICOM_VTABLE(IROTData
)* lpvtbl2
; /* VTable relative to the IROTData interface.*/
49 ULONG ref
; /* reference counter for this object */
53 /********************************************************************************/
54 /* AntiMoniker prototype functions : */
56 /* IUnknown prototype functions */
57 static HRESULT WINAPI
AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
);
58 static ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker
* iface
);
59 static ULONG WINAPI
AntiMonikerImpl_Release(IMoniker
* iface
);
61 /* IPersist prototype functions */
62 static HRESULT WINAPI
AntiMonikerImpl_GetClassID(IMoniker
* iface
, CLSID
*pClassID
);
64 /* IPersistStream prototype functions */
65 static HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker
* iface
);
66 static HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker
* iface
, IStream
* pStm
);
67 static HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
);
68 static HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
);
70 /* IMoniker prototype functions */
71 static HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
72 static HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
73 static HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker
* iface
,IBindCtx
* pbc
, DWORD dwReduceHowFar
,IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
);
74 static HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker
* iface
,IMoniker
* pmkRight
,BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
);
75 static HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
);
76 static HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
);
77 static HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
);
78 static HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, IMoniker
* pmkNewlyRunning
);
79 static HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
, FILETIME
* pAntiTime
);
80 static HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
);
81 static HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
, IMoniker
** ppmkPrefix
);
82 static HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
);
83 static HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
);
84 static HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
);
85 static HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
);
87 /********************************************************************************/
88 /* IROTData prototype functions */
90 /* IUnknown prototype functions */
91 static HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData
* iface
,REFIID riid
,VOID
** ppvObject
);
92 static ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
* iface
);
93 static ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
);
95 /* IROTData prototype function */
96 static HRESULT WINAPI
AntiMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,BYTE
* pbData
,ULONG cbMax
,ULONG
* pcbData
);
98 /* Local function used by AntiMoniker implementation */
99 HRESULT WINAPI
AntiMonikerImpl_Construct(AntiMonikerImpl
* iface
);
100 HRESULT WINAPI
AntiMonikerImpl_Destroy(AntiMonikerImpl
* iface
);
102 /********************************************************************************/
103 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
104 /* IPersistStream and IMoniker functions. */
105 static ICOM_VTABLE(IMoniker
) VT_AntiMonikerImpl
=
107 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
108 AntiMonikerImpl_QueryInterface
,
109 AntiMonikerImpl_AddRef
,
110 AntiMonikerImpl_Release
,
111 AntiMonikerImpl_GetClassID
,
112 AntiMonikerImpl_IsDirty
,
113 AntiMonikerImpl_Load
,
114 AntiMonikerImpl_Save
,
115 AntiMonikerImpl_GetSizeMax
,
116 AntiMonikerImpl_BindToObject
,
117 AntiMonikerImpl_BindToStorage
,
118 AntiMonikerImpl_Reduce
,
119 AntiMonikerImpl_ComposeWith
,
120 AntiMonikerImpl_Enum
,
121 AntiMonikerImpl_IsEqual
,
122 AntiMonikerImpl_Hash
,
123 AntiMonikerImpl_IsRunning
,
124 AntiMonikerImpl_GetTimeOfLastChange
,
125 AntiMonikerImpl_Inverse
,
126 AntiMonikerImpl_CommonPrefixWith
,
127 AntiMonikerImpl_RelativePathTo
,
128 AntiMonikerImpl_GetDisplayName
,
129 AntiMonikerImpl_ParseDisplayName
,
130 AntiMonikerImpl_IsSystemMoniker
133 /********************************************************************************/
134 /* Virtual function table for the IROTData class. */
135 static ICOM_VTABLE(IROTData
) VT_ROTDataImpl
=
137 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
138 AntiMonikerROTDataImpl_QueryInterface
,
139 AntiMonikerROTDataImpl_AddRef
,
140 AntiMonikerROTDataImpl_Release
,
141 AntiMonikerROTDataImpl_GetComparaisonData
144 /*******************************************************************************
145 * AntiMoniker_QueryInterface
146 *******************************************************************************/
147 HRESULT WINAPI
AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
149 ICOM_THIS(AntiMonikerImpl
,iface
);
151 TRACE("(%p,%p,%p)\n",This
,riid
,ppvObject
);
153 /* Perform a sanity check on the parameters.*/
154 if ( (This
==0) || (ppvObject
==0) )
157 /* Initialize the return parameter */
160 /* Compare the riid with the interface IDs implemented by this object.*/
161 if (IsEqualIID(&IID_IUnknown
, riid
) ||
162 IsEqualIID(&IID_IPersist
, riid
) ||
163 IsEqualIID(&IID_IPersistStream
, riid
) ||
164 IsEqualIID(&IID_IMoniker
, riid
)
167 else if (IsEqualIID(&IID_IROTData
, riid
))
168 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
170 /* Check that we obtained an interface.*/
172 return E_NOINTERFACE
;
174 /* Query Interface always increases the reference count by one when it is successful */
175 AntiMonikerImpl_AddRef(iface
);
180 /******************************************************************************
182 ******************************************************************************/
183 ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker
* iface
)
185 ICOM_THIS(AntiMonikerImpl
,iface
);
187 TRACE("(%p)\n",This
);
189 return ++(This
->ref
);
192 /******************************************************************************
193 * AntiMoniker_Release
194 ******************************************************************************/
195 ULONG WINAPI
AntiMonikerImpl_Release(IMoniker
* iface
)
197 ICOM_THIS(AntiMonikerImpl
,iface
);
199 TRACE("(%p)\n",This
);
203 /* destroy the object if there's no more reference on it */
206 AntiMonikerImpl_Destroy(This
);
213 /******************************************************************************
214 * AntiMoniker_GetClassID
215 ******************************************************************************/
216 HRESULT WINAPI
AntiMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
218 TRACE("(%p,%p),stub!\n",iface
,pClassID
);
223 *pClassID
= CLSID_AntiMoniker
;
228 /******************************************************************************
229 * AntiMoniker_IsDirty
230 ******************************************************************************/
231 HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker
* iface
)
233 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
234 method in the OLE-provided moniker interfaces always return S_FALSE because
235 their internal state never changes. */
237 TRACE("(%p)\n",iface
);
242 /******************************************************************************
244 ******************************************************************************/
245 HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
247 DWORD constant
=1,dwbuffer
;
250 /* data read by this function is only a DWORD constant (must be 1) ! */
251 res
=IStream_Read(pStm
,&dwbuffer
,sizeof(DWORD
),NULL
);
253 if (SUCCEEDED(res
)&& dwbuffer
!=constant
)
259 /******************************************************************************
261 ******************************************************************************/
262 HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker
* iface
,IStream
* pStm
,BOOL fClearDirty
)
267 /* data writen by this function is only a DWORD constant seted to 1 ! */
268 res
=IStream_Write(pStm
,&constant
,sizeof(constant
),NULL
);
273 /******************************************************************************
274 * AntiMoniker_GetSizeMax
275 ******************************************************************************/
276 HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker
* iface
,
277 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
279 TRACE("(%p,%p)\n",iface
,pcbSize
);
284 /* for more details see AntiMonikerImpl_Save coments */
286 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
287 /* more than the number of bytes used by AntiMoniker::Save function */
288 pcbSize
->s
.LowPart
= sizeof(DWORD
)+16;
290 pcbSize
->s
.HighPart
=0;
295 /******************************************************************************
296 * AntiMoniker_Construct (local function)
297 *******************************************************************************/
298 HRESULT WINAPI
AntiMonikerImpl_Construct(AntiMonikerImpl
* This
)
301 TRACE("(%p)\n",This
);
303 /* Initialize the virtual fgunction table. */
304 This
->lpvtbl1
= &VT_AntiMonikerImpl
;
305 This
->lpvtbl2
= &VT_ROTDataImpl
;
311 /******************************************************************************
312 * AntiMoniker_Destroy (local function)
313 *******************************************************************************/
314 HRESULT WINAPI
AntiMonikerImpl_Destroy(AntiMonikerImpl
* This
)
316 TRACE("(%p)\n",This
);
318 return HeapFree(GetProcessHeap(),0,This
);
321 /******************************************************************************
322 * AntiMoniker_BindToObject
323 ******************************************************************************/
324 HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker
* iface
,
330 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
334 /******************************************************************************
335 * AntiMoniker_BindToStorage
336 ******************************************************************************/
337 HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker
* iface
,
343 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
347 /******************************************************************************
349 ******************************************************************************/
350 HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker
* iface
,
352 DWORD dwReduceHowFar
,
353 IMoniker
** ppmkToLeft
,
354 IMoniker
** ppmkReduced
)
356 TRACE("(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
358 if (ppmkReduced
==NULL
)
361 AntiMonikerImpl_AddRef(iface
);
365 return MK_S_REDUCED_TO_SELF
;
367 /******************************************************************************
368 * AntiMoniker_ComposeWith
369 ******************************************************************************/
370 HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker
* iface
,
372 BOOL fOnlyIfNotGeneric
,
373 IMoniker
** ppmkComposite
)
376 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
378 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
383 if (fOnlyIfNotGeneric
)
384 return MK_E_NEEDGENERIC
;
386 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
389 /******************************************************************************
391 ******************************************************************************/
392 HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
394 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
396 if (ppenumMoniker
== NULL
)
399 *ppenumMoniker
= NULL
;
404 /******************************************************************************
405 * AntiMoniker_IsEqual
406 ******************************************************************************/
407 HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
411 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
413 if (pmkOtherMoniker
==NULL
)
416 IMoniker_IsSystemMoniker(pmkOtherMoniker
,&mkSys
);
418 if (mkSys
==MKSYS_ANTIMONIKER
)
424 /******************************************************************************
426 ******************************************************************************/
427 HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
437 /******************************************************************************
438 * AntiMoniker_IsRunning
439 ******************************************************************************/
440 HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker
* iface
,
443 IMoniker
* pmkNewlyRunning
)
445 IRunningObjectTable
* rot
;
448 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
453 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
458 res
= IRunningObjectTable_IsRunning(rot
,iface
);
460 IRunningObjectTable_Release(rot
);
465 /******************************************************************************
466 * AntiMoniker_GetTimeOfLastChange
467 ******************************************************************************/
468 HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
473 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pAntiTime
);
477 /******************************************************************************
478 * AntiMoniker_Inverse
479 ******************************************************************************/
480 HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
482 TRACE("(%p,%p)\n",iface
,ppmk
);
489 return MK_E_NOINVERSE
;
492 /******************************************************************************
493 * AntiMoniker_CommonPrefixWith
494 ******************************************************************************/
495 HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
499 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
501 if(mkSys
==MKSYS_ITEMMONIKER
){
503 IMoniker_AddRef(iface
);
507 IMoniker_AddRef(iface
);
512 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
515 /******************************************************************************
516 * AntiMoniker_RelativePathTo
517 ******************************************************************************/
518 HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
520 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
522 if (ppmkRelPath
==NULL
)
525 IMoniker_AddRef(pmOther
);
527 *ppmkRelPath
=pmOther
;
532 /******************************************************************************
533 * AntiMoniker_GetDisplayName
534 ******************************************************************************/
535 HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker
* iface
,
538 LPOLESTR
*ppszDisplayName
)
540 WCHAR back
[]={'\\','.','.',0};
542 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
544 if (ppszDisplayName
==NULL
)
547 if (pmkToLeft
!=NULL
){
548 FIXME("() pmkToLeft!=NULL not implemented \n");
552 *ppszDisplayName
=CoTaskMemAlloc(sizeof(back
));
554 if (*ppszDisplayName
==NULL
)
555 return E_OUTOFMEMORY
;
557 strcpyW(*ppszDisplayName
,back
);
562 /******************************************************************************
563 * AntiMoniker_ParseDisplayName
564 ******************************************************************************/
565 HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
,
568 LPOLESTR pszDisplayName
,
572 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pszDisplayName
,pchEaten
,ppmkOut
);
576 /******************************************************************************
577 * AntiMoniker_IsSystemMoniker
578 ******************************************************************************/
579 HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
581 TRACE("(%p,%p)\n",iface
,pwdMksys
);
586 (*pwdMksys
)=MKSYS_ANTIMONIKER
;
591 /*******************************************************************************
592 * AntiMonikerIROTData_QueryInterface
593 *******************************************************************************/
594 HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
597 ICOM_THIS_From_IROTData(IMoniker
, iface
);
599 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
601 return AntiMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
604 /***********************************************************************
605 * AntiMonikerIROTData_AddRef
607 ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
*iface
)
609 ICOM_THIS_From_IROTData(IMoniker
, iface
);
611 TRACE("(%p)\n",iface
);
613 return AntiMonikerImpl_AddRef(This
);
616 /***********************************************************************
617 * AntiMonikerIROTData_Release
619 ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
)
621 ICOM_THIS_From_IROTData(IMoniker
, iface
);
623 TRACE("(%p)\n",iface
);
625 return AntiMonikerImpl_Release(This
);
628 /******************************************************************************
629 * AntiMonikerIROTData_GetComparaisonData
630 ******************************************************************************/
631 HRESULT WINAPI
AntiMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,
640 /******************************************************************************
641 * CreateAntiMoniker [OLE32.51]
642 ******************************************************************************/
643 HRESULT WINAPI
CreateAntiMoniker(LPMONIKER
* ppmk
)
645 AntiMonikerImpl
* newAntiMoniker
= 0;
647 IID riid
=IID_IMoniker
;
649 TRACE("(%p)\n",ppmk
);
651 newAntiMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl
));
653 if (newAntiMoniker
== 0)
654 return STG_E_INSUFFICIENTMEMORY
;
656 hr
= AntiMonikerImpl_Construct(newAntiMoniker
);
660 HeapFree(GetProcessHeap(),0,newAntiMoniker
);
664 hr
= AntiMonikerImpl_QueryInterface((IMoniker
*)newAntiMoniker
,&riid
,(void**)ppmk
);