Release 1.3.1.
[wine/hramrach.git] / dlls / ole32 / antimoniker.c
blob7f040363499a5e20c1d4bc653ca49d8cbf01651a
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <string.h>
25 #define COBJMACROS
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
32 #include "objbase.h"
33 #include "wine/debug.h"
34 #include "moniker.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 */
51 } AntiMonikerImpl;
53 static inline IMoniker *impl_from_IROTData( IROTData *iface )
55 return (IMoniker *)((char*)iface - FIELD_OFFSET(AntiMonikerImpl, lpvtbl2));
59 /*******************************************************************************
60 * AntiMoniker_QueryInterface
61 *******************************************************************************/
62 static HRESULT WINAPI
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 ( ppvObject==0 )
71 return E_INVALIDARG;
73 /* Initialize the return parameter */
74 *ppvObject = 0;
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))
81 *ppvObject = iface;
82 else if (IsEqualIID(&IID_IROTData, riid))
83 *ppvObject = &This->lpvtbl2;
84 else if (IsEqualIID(&IID_IMarshal, riid))
86 HRESULT hr = S_OK;
87 if (!This->pMarshal)
88 hr = MonikerMarshal_Create(iface, &This->pMarshal);
89 if (hr != S_OK)
90 return hr;
91 return IUnknown_QueryInterface(This->pMarshal, riid, ppvObject);
94 /* Check that we obtained an interface.*/
95 if ((*ppvObject)==0)
96 return E_NOINTERFACE;
98 /* always increase the reference count by one when it is successful */
99 IMoniker_AddRef(iface);
101 return S_OK;
104 /******************************************************************************
105 * AntiMoniker_AddRef
106 ******************************************************************************/
107 static ULONG WINAPI
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 ******************************************************************************/
120 static ULONG WINAPI
121 AntiMonikerImpl_Release(IMoniker* iface)
123 AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
124 ULONG ref;
126 TRACE("(%p)\n",This);
128 ref = InterlockedDecrement(&This->ref);
130 /* destroy the object if there's no more reference on it */
131 if (ref == 0)
133 if (This->pMarshal) IUnknown_Release(This->pMarshal);
134 HeapFree(GetProcessHeap(),0,This);
137 return ref;
140 /******************************************************************************
141 * AntiMoniker_GetClassID
142 ******************************************************************************/
143 static HRESULT WINAPI
144 AntiMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
146 TRACE("(%p,%p)\n",iface,pClassID);
148 if (pClassID==NULL)
149 return E_POINTER;
151 *pClassID = CLSID_AntiMoniker;
153 return S_OK;
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);
168 return S_FALSE;
171 /******************************************************************************
172 * AntiMoniker_Load
173 ******************************************************************************/
174 static HRESULT WINAPI
175 AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
177 DWORD constant=1,dwbuffer;
178 HRESULT res;
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)
184 return E_FAIL;
186 return res;
189 /******************************************************************************
190 * AntiMoniker_Save
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
203 * PARAMS
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);
211 if (!pcbSize)
212 return E_POINTER;
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;
225 return S_OK;
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);
236 return E_NOTIMPL;
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);
247 return E_NOTIMPL;
250 /******************************************************************************
251 * AntiMoniker_Reduce
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)
260 return E_POINTER;
262 AntiMonikerImpl_AddRef(iface);
264 *ppmkReduced=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))
279 return E_POINTER;
281 *ppmkComposite=0;
283 if (fOnlyIfNotGeneric)
284 return MK_E_NEEDGENERIC;
285 else
286 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
289 /******************************************************************************
290 * AntiMoniker_Enum
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)
298 return E_POINTER;
300 *ppenumMoniker = NULL;
302 return S_OK;
305 /******************************************************************************
306 * AntiMoniker_IsEqual
307 ******************************************************************************/
308 static HRESULT WINAPI
309 AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
311 DWORD mkSys;
313 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
315 if (pmkOtherMoniker==NULL)
316 return S_FALSE;
318 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
320 if (mkSys==MKSYS_ANTIMONIKER)
321 return S_OK;
322 else
323 return S_FALSE;
326 /******************************************************************************
327 * AntiMoniker_Hash
328 ******************************************************************************/
329 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
331 if (pdwHash==NULL)
332 return E_POINTER;
334 *pdwHash = 0x80000001;
336 return S_OK;
339 /******************************************************************************
340 * AntiMoniker_IsRunning
341 ******************************************************************************/
342 static HRESULT WINAPI
343 AntiMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
344 IMoniker* pmkNewlyRunning)
346 IRunningObjectTable* rot;
347 HRESULT res;
349 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
351 if (pbc==NULL)
352 return E_INVALIDARG;
354 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
356 if (FAILED(res))
357 return res;
359 res = IRunningObjectTable_IsRunning(rot,iface);
361 IRunningObjectTable_Release(rot);
363 return res;
366 /******************************************************************************
367 * AntiMoniker_GetTimeOfLastChange
368 ******************************************************************************/
369 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
370 IBindCtx* pbc,
371 IMoniker* pmkToLeft,
372 FILETIME* pAntiTime)
374 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
375 return E_NOTIMPL;
378 /******************************************************************************
379 * AntiMoniker_Inverse
380 ******************************************************************************/
381 static HRESULT WINAPI
382 AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
384 TRACE("(%p,%p)\n",iface,ppmk);
386 if (ppmk==NULL)
387 return E_POINTER;
389 *ppmk=0;
391 return MK_E_NOINVERSE;
394 /******************************************************************************
395 * AntiMoniker_CommonPrefixWith
396 ******************************************************************************/
397 static HRESULT WINAPI
398 AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
400 DWORD mkSys;
402 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
404 if(mkSys==MKSYS_ANTIMONIKER){
406 IMoniker_AddRef(iface);
408 *ppmkPrefix=iface;
410 IMoniker_AddRef(iface);
412 return MK_S_US;
414 else
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)
427 return E_POINTER;
429 IMoniker_AddRef(pmOther);
431 *ppmkRelPath=pmOther;
433 return MK_S_HIM;
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)
448 return E_POINTER;
450 if (pmkToLeft!=NULL){
451 FIXME("() pmkToLeft!=NULL not implemented\n");
452 return E_NOTIMPL;
455 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
457 if (*ppszDisplayName==NULL)
458 return E_OUTOFMEMORY;
460 lstrcpyW(*ppszDisplayName,back);
462 return S_OK;
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);
474 return E_NOTIMPL;
477 /******************************************************************************
478 * AntiMoniker_IsSystemMoniker
479 ******************************************************************************/
480 static HRESULT WINAPI
481 AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
483 TRACE("(%p,%p)\n",iface,pwdMksys);
485 if (!pwdMksys)
486 return E_POINTER;
488 (*pwdMksys)=MKSYS_ANTIMONIKER;
490 return S_OK;
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)
537 DWORD constant = 1;
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));
548 return S_OK;
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;
602 This->ref = 0;
603 This->pMarshal = NULL;
605 return S_OK;
608 /******************************************************************************
609 * CreateAntiMoniker [OLE32.@]
610 ******************************************************************************/
611 HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
613 AntiMonikerImpl* newAntiMoniker;
614 HRESULT hr;
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);
624 if (FAILED(hr))
626 HeapFree(GetProcessHeap(),0,newAntiMoniker);
627 return hr;
630 return AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&IID_IMoniker,(void**)ppmk);
633 static HRESULT WINAPI AntiMonikerCF_QueryInterface(LPCLASSFACTORY iface,
634 REFIID riid, LPVOID *ppv)
636 *ppv = NULL;
637 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
639 *ppv = iface;
640 IUnknown_AddRef(iface);
641 return S_OK;
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)
659 IMoniker *pMoniker;
660 HRESULT hr;
662 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);
664 *ppv = NULL;
666 if (pUnk)
667 return CLASS_E_NOAGGREGATION;
669 hr = CreateAntiMoniker(&pMoniker);
670 if (FAILED(hr))
671 return hr;
673 hr = IMoniker_QueryInterface(pMoniker, riid, ppv);
675 if (FAILED(hr))
676 IMoniker_Release(pMoniker);
678 return hr;
681 static HRESULT WINAPI AntiMonikerCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
683 FIXME("(%d), stub!\n",fLock);
684 return S_OK;
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);