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 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 IROTDataVtbl
* lpvtbl2
; /* VTable relative to the IROTData interface.*/
52 ULONG ref
; /* reference counter for this object */
57 /*******************************************************************************
58 * AntiMoniker_QueryInterface
59 *******************************************************************************/
61 AntiMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
63 AntiMonikerImpl
*This
= (AntiMonikerImpl
*)iface
;
65 TRACE("(%p,%p,%p)\n",This
,riid
,ppvObject
);
67 /* Perform a sanity check on the parameters.*/
68 if ( (This
==0) || (ppvObject
==0) )
71 /* Initialize the return parameter */
74 /* Compare the riid with the interface IDs implemented by this object.*/
75 if (IsEqualIID(&IID_IUnknown
, riid
) ||
76 IsEqualIID(&IID_IPersist
, riid
) ||
77 IsEqualIID(&IID_IPersistStream
, riid
) ||
78 IsEqualIID(&IID_IMoniker
, riid
))
80 else if (IsEqualIID(&IID_IROTData
, riid
))
81 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
83 /* Check that we obtained an interface.*/
87 /* always increase the reference count by one when it is successful */
88 IMoniker_AddRef(iface
);
93 /******************************************************************************
95 ******************************************************************************/
97 AntiMonikerImpl_AddRef(IMoniker
* iface
)
99 AntiMonikerImpl
*This
= (AntiMonikerImpl
*)iface
;
101 TRACE("(%p)\n",This
);
103 return InterlockedIncrement(&This
->ref
);
106 /******************************************************************************
107 * AntiMoniker_Release
108 ******************************************************************************/
110 AntiMonikerImpl_Release(IMoniker
* iface
)
112 AntiMonikerImpl
*This
= (AntiMonikerImpl
*)iface
;
115 TRACE("(%p)\n",This
);
117 ref
= InterlockedDecrement(&This
->ref
);
119 /* destroy the object if there's no more reference on it */
120 if (ref
== 0) HeapFree(GetProcessHeap(),0,This
);
125 /******************************************************************************
126 * AntiMoniker_GetClassID
127 ******************************************************************************/
128 static HRESULT WINAPI
129 AntiMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
131 TRACE("(%p,%p),stub!\n",iface
,pClassID
);
136 *pClassID
= CLSID_AntiMoniker
;
141 /******************************************************************************
142 * AntiMoniker_IsDirty
143 ******************************************************************************/
144 static HRESULT WINAPI
145 AntiMonikerImpl_IsDirty(IMoniker
* iface
)
147 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
148 method in the OLE-provided moniker interfaces always return S_FALSE because
149 their internal state never changes. */
151 TRACE("(%p)\n",iface
);
156 /******************************************************************************
158 ******************************************************************************/
159 static HRESULT WINAPI
160 AntiMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
162 DWORD constant
=1,dwbuffer
;
165 /* data read by this function is only a DWORD constant (must be 1) ! */
166 res
=IStream_Read(pStm
,&dwbuffer
,sizeof(DWORD
),NULL
);
168 if (SUCCEEDED(res
)&& dwbuffer
!=constant
)
174 /******************************************************************************
176 ******************************************************************************/
177 static HRESULT WINAPI
178 AntiMonikerImpl_Save(IMoniker
* iface
,IStream
* pStm
,BOOL fClearDirty
)
183 /* data written by this function is only a DWORD constant set to 1 ! */
184 res
=IStream_Write(pStm
,&constant
,sizeof(constant
),NULL
);
189 /******************************************************************************
190 * AntiMoniker_GetSizeMax
193 * pcbSize [out] Pointer to size of stream needed to save object
194 ******************************************************************************/
195 static HRESULT WINAPI
196 AntiMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
)
198 TRACE("(%p,%p)\n",iface
,pcbSize
);
203 /* for more details see AntiMonikerImpl_Save coments */
206 * Normally the sizemax must be sizeof DWORD, but
207 * I tested this function it usually return 16 bytes
208 * more than the number of bytes used by AntiMoniker::Save function
210 pcbSize
->u
.LowPart
= sizeof(DWORD
)+16;
212 pcbSize
->u
.HighPart
=0;
217 /******************************************************************************
218 * AntiMoniker_BindToObject
219 ******************************************************************************/
220 static HRESULT WINAPI
221 AntiMonikerImpl_BindToObject(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
,
222 REFIID riid
, VOID
** ppvResult
)
224 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
228 /******************************************************************************
229 * AntiMoniker_BindToStorage
230 ******************************************************************************/
231 static HRESULT WINAPI
232 AntiMonikerImpl_BindToStorage(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 /******************************************************************************
241 ******************************************************************************/
242 static HRESULT WINAPI
243 AntiMonikerImpl_Reduce(IMoniker
* iface
, IBindCtx
* pbc
, DWORD dwReduceHowFar
,
244 IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
)
246 TRACE("(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
248 if (ppmkReduced
==NULL
)
251 AntiMonikerImpl_AddRef(iface
);
255 return MK_S_REDUCED_TO_SELF
;
257 /******************************************************************************
258 * AntiMoniker_ComposeWith
259 ******************************************************************************/
260 static HRESULT WINAPI
261 AntiMonikerImpl_ComposeWith(IMoniker
* iface
, IMoniker
* pmkRight
,
262 BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
)
265 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
267 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
272 if (fOnlyIfNotGeneric
)
273 return MK_E_NEEDGENERIC
;
275 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
278 /******************************************************************************
280 ******************************************************************************/
281 static HRESULT WINAPI
282 AntiMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
284 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
286 if (ppenumMoniker
== NULL
)
289 *ppenumMoniker
= NULL
;
294 /******************************************************************************
295 * AntiMoniker_IsEqual
296 ******************************************************************************/
297 static HRESULT WINAPI
298 AntiMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
302 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
304 if (pmkOtherMoniker
==NULL
)
307 IMoniker_IsSystemMoniker(pmkOtherMoniker
,&mkSys
);
309 if (mkSys
==MKSYS_ANTIMONIKER
)
315 /******************************************************************************
317 ******************************************************************************/
318 static HRESULT WINAPI
AntiMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
328 /******************************************************************************
329 * AntiMoniker_IsRunning
330 ******************************************************************************/
331 static HRESULT WINAPI
332 AntiMonikerImpl_IsRunning(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
,
333 IMoniker
* pmkNewlyRunning
)
335 IRunningObjectTable
* rot
;
338 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
343 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
348 res
= IRunningObjectTable_IsRunning(rot
,iface
);
350 IRunningObjectTable_Release(rot
);
355 /******************************************************************************
356 * AntiMoniker_GetTimeOfLastChange
357 ******************************************************************************/
358 static HRESULT WINAPI
AntiMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
363 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pAntiTime
);
367 /******************************************************************************
368 * AntiMoniker_Inverse
369 ******************************************************************************/
370 static HRESULT WINAPI
371 AntiMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
373 TRACE("(%p,%p)\n",iface
,ppmk
);
380 return MK_E_NOINVERSE
;
383 /******************************************************************************
384 * AntiMoniker_CommonPrefixWith
385 ******************************************************************************/
386 static HRESULT WINAPI
387 AntiMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
391 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
393 if(mkSys
==MKSYS_ITEMMONIKER
){
395 IMoniker_AddRef(iface
);
399 IMoniker_AddRef(iface
);
404 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
407 /******************************************************************************
408 * AntiMoniker_RelativePathTo
409 ******************************************************************************/
410 static HRESULT WINAPI
411 AntiMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
413 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
415 if (ppmkRelPath
==NULL
)
418 IMoniker_AddRef(pmOther
);
420 *ppmkRelPath
=pmOther
;
425 /******************************************************************************
426 * AntiMoniker_GetDisplayName
427 ******************************************************************************/
428 static HRESULT WINAPI
429 AntiMonikerImpl_GetDisplayName(IMoniker
* iface
, IBindCtx
* pbc
,
430 IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
)
432 static const WCHAR back
[]={'\\','.','.',0};
434 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
436 if (ppszDisplayName
==NULL
)
439 if (pmkToLeft
!=NULL
){
440 FIXME("() pmkToLeft!=NULL not implemented \n");
444 *ppszDisplayName
=CoTaskMemAlloc(sizeof(back
));
446 if (*ppszDisplayName
==NULL
)
447 return E_OUTOFMEMORY
;
449 lstrcpyW(*ppszDisplayName
,back
);
454 /******************************************************************************
455 * AntiMoniker_ParseDisplayName
456 ******************************************************************************/
457 static HRESULT WINAPI
458 AntiMonikerImpl_ParseDisplayName(IMoniker
* iface
, IBindCtx
* pbc
,
459 IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
,
460 ULONG
* pchEaten
, IMoniker
** ppmkOut
)
462 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pszDisplayName
,pchEaten
,ppmkOut
);
466 /******************************************************************************
467 * AntiMoniker_IsSystemMoniker
468 ******************************************************************************/
469 static HRESULT WINAPI
470 AntiMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
472 TRACE("(%p,%p)\n",iface
,pwdMksys
);
477 (*pwdMksys
)=MKSYS_ANTIMONIKER
;
482 /*******************************************************************************
483 * AntiMonikerIROTData_QueryInterface
484 *******************************************************************************/
485 static HRESULT WINAPI
486 AntiMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
488 ICOM_THIS_From_IROTData(IMoniker
, iface
);
490 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
492 return AntiMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
495 /***********************************************************************
496 * AntiMonikerIROTData_AddRef
498 static ULONG WINAPI
AntiMonikerROTDataImpl_AddRef(IROTData
*iface
)
500 ICOM_THIS_From_IROTData(IMoniker
, iface
);
502 TRACE("(%p)\n",iface
);
504 return AntiMonikerImpl_AddRef(This
);
507 /***********************************************************************
508 * AntiMonikerIROTData_Release
510 static ULONG WINAPI
AntiMonikerROTDataImpl_Release(IROTData
* iface
)
512 ICOM_THIS_From_IROTData(IMoniker
, iface
);
514 TRACE("(%p)\n",iface
);
516 return AntiMonikerImpl_Release(This
);
519 /******************************************************************************
520 * AntiMonikerIROTData_GetComparaisonData
521 ******************************************************************************/
522 static HRESULT WINAPI
523 AntiMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
, BYTE
* pbData
,
524 ULONG cbMax
, ULONG
* pcbData
)
530 /********************************************************************************/
531 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
532 /* IPersistStream and IMoniker functions. */
533 static IMonikerVtbl VT_AntiMonikerImpl
=
535 AntiMonikerImpl_QueryInterface
,
536 AntiMonikerImpl_AddRef
,
537 AntiMonikerImpl_Release
,
538 AntiMonikerImpl_GetClassID
,
539 AntiMonikerImpl_IsDirty
,
540 AntiMonikerImpl_Load
,
541 AntiMonikerImpl_Save
,
542 AntiMonikerImpl_GetSizeMax
,
543 AntiMonikerImpl_BindToObject
,
544 AntiMonikerImpl_BindToStorage
,
545 AntiMonikerImpl_Reduce
,
546 AntiMonikerImpl_ComposeWith
,
547 AntiMonikerImpl_Enum
,
548 AntiMonikerImpl_IsEqual
,
549 AntiMonikerImpl_Hash
,
550 AntiMonikerImpl_IsRunning
,
551 AntiMonikerImpl_GetTimeOfLastChange
,
552 AntiMonikerImpl_Inverse
,
553 AntiMonikerImpl_CommonPrefixWith
,
554 AntiMonikerImpl_RelativePathTo
,
555 AntiMonikerImpl_GetDisplayName
,
556 AntiMonikerImpl_ParseDisplayName
,
557 AntiMonikerImpl_IsSystemMoniker
560 /********************************************************************************/
561 /* Virtual function table for the IROTData class. */
562 static IROTDataVtbl VT_ROTDataImpl
=
564 AntiMonikerROTDataImpl_QueryInterface
,
565 AntiMonikerROTDataImpl_AddRef
,
566 AntiMonikerROTDataImpl_Release
,
567 AntiMonikerROTDataImpl_GetComparaisonData
570 /******************************************************************************
571 * AntiMoniker_Construct (local function)
572 *******************************************************************************/
573 static HRESULT
AntiMonikerImpl_Construct(AntiMonikerImpl
* This
)
576 TRACE("(%p)\n",This
);
578 /* Initialize the virtual fgunction table. */
579 This
->lpvtbl1
= &VT_AntiMonikerImpl
;
580 This
->lpvtbl2
= &VT_ROTDataImpl
;
586 /******************************************************************************
587 * CreateAntiMoniker [OLE32.@]
588 ******************************************************************************/
589 HRESULT WINAPI
CreateAntiMoniker(LPMONIKER
* ppmk
)
591 AntiMonikerImpl
* newAntiMoniker
= 0;
593 IID riid
=IID_IMoniker
;
595 TRACE("(%p)\n",ppmk
);
597 newAntiMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl
));
599 if (newAntiMoniker
== 0)
600 return STG_E_INSUFFICIENTMEMORY
;
602 hr
= AntiMonikerImpl_Construct(newAntiMoniker
);
605 HeapFree(GetProcessHeap(),0,newAntiMoniker
);
609 hr
= AntiMonikerImpl_QueryInterface((IMoniker
*)newAntiMoniker
,&riid
,(void**)ppmk
);