ddraw: Register / unregister the ddraw window class from DllMain().
[wine/testsucceed.git] / dlls / ole32 / antimoniker.c
blob69e0a902f789a9e108f2649536a867dd1bf5490b
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 ( (This==0) || (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 DWORD constant=1;
196 HRESULT res;
198 /* data written by this function is only a DWORD constant set to 1 ! */
199 res=IStream_Write(pStm,&constant,sizeof(constant),NULL);
201 return res;
204 /******************************************************************************
205 * AntiMoniker_GetSizeMax
207 * PARAMS
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);
215 if (!pcbSize)
216 return E_POINTER;
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;
229 return S_OK;
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);
240 return E_NOTIMPL;
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);
251 return E_NOTIMPL;
254 /******************************************************************************
255 * AntiMoniker_Reduce
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)
264 return E_POINTER;
266 AntiMonikerImpl_AddRef(iface);
268 *ppmkReduced=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))
283 return E_POINTER;
285 *ppmkComposite=0;
287 if (fOnlyIfNotGeneric)
288 return MK_E_NEEDGENERIC;
289 else
290 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
293 /******************************************************************************
294 * AntiMoniker_Enum
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)
302 return E_POINTER;
304 *ppenumMoniker = NULL;
306 return S_OK;
309 /******************************************************************************
310 * AntiMoniker_IsEqual
311 ******************************************************************************/
312 static HRESULT WINAPI
313 AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
315 DWORD mkSys;
317 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
319 if (pmkOtherMoniker==NULL)
320 return S_FALSE;
322 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
324 if (mkSys==MKSYS_ANTIMONIKER)
325 return S_OK;
326 else
327 return S_FALSE;
330 /******************************************************************************
331 * AntiMoniker_Hash
332 ******************************************************************************/
333 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
335 if (pdwHash==NULL)
336 return E_POINTER;
338 *pdwHash = 0x80000001;
340 return S_OK;
343 /******************************************************************************
344 * AntiMoniker_IsRunning
345 ******************************************************************************/
346 static HRESULT WINAPI
347 AntiMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
348 IMoniker* pmkNewlyRunning)
350 IRunningObjectTable* rot;
351 HRESULT res;
353 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
355 if (pbc==NULL)
356 return E_INVALIDARG;
358 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
360 if (FAILED(res))
361 return res;
363 res = IRunningObjectTable_IsRunning(rot,iface);
365 IRunningObjectTable_Release(rot);
367 return res;
370 /******************************************************************************
371 * AntiMoniker_GetTimeOfLastChange
372 ******************************************************************************/
373 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
374 IBindCtx* pbc,
375 IMoniker* pmkToLeft,
376 FILETIME* pAntiTime)
378 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
379 return E_NOTIMPL;
382 /******************************************************************************
383 * AntiMoniker_Inverse
384 ******************************************************************************/
385 static HRESULT WINAPI
386 AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
388 TRACE("(%p,%p)\n",iface,ppmk);
390 if (ppmk==NULL)
391 return E_POINTER;
393 *ppmk=0;
395 return MK_E_NOINVERSE;
398 /******************************************************************************
399 * AntiMoniker_CommonPrefixWith
400 ******************************************************************************/
401 static HRESULT WINAPI
402 AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
404 DWORD mkSys;
406 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
408 if(mkSys==MKSYS_ANTIMONIKER){
410 IMoniker_AddRef(iface);
412 *ppmkPrefix=iface;
414 IMoniker_AddRef(iface);
416 return MK_S_US;
418 else
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)
431 return E_POINTER;
433 IMoniker_AddRef(pmOther);
435 *ppmkRelPath=pmOther;
437 return MK_S_HIM;
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)
452 return E_POINTER;
454 if (pmkToLeft!=NULL){
455 FIXME("() pmkToLeft!=NULL not implemented\n");
456 return E_NOTIMPL;
459 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
461 if (*ppszDisplayName==NULL)
462 return E_OUTOFMEMORY;
464 lstrcpyW(*ppszDisplayName,back);
466 return S_OK;
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);
478 return E_NOTIMPL;
481 /******************************************************************************
482 * AntiMoniker_IsSystemMoniker
483 ******************************************************************************/
484 static HRESULT WINAPI
485 AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
487 TRACE("(%p,%p)\n",iface,pwdMksys);
489 if (!pwdMksys)
490 return E_POINTER;
492 (*pwdMksys)=MKSYS_ANTIMONIKER;
494 return S_OK;
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)
541 DWORD constant = 1;
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));
552 return S_OK;
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;
606 This->ref = 0;
607 This->pMarshal = NULL;
609 return S_OK;
612 /******************************************************************************
613 * CreateAntiMoniker [OLE32.@]
614 ******************************************************************************/
615 HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
617 AntiMonikerImpl* newAntiMoniker = 0;
618 HRESULT hr = S_OK;
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);
629 if (FAILED(hr))
631 HeapFree(GetProcessHeap(),0,newAntiMoniker);
632 return hr;
635 hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk);
637 return hr;
640 static HRESULT WINAPI AntiMonikerCF_QueryInterface(LPCLASSFACTORY iface,
641 REFIID riid, LPVOID *ppv)
643 *ppv = NULL;
644 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
646 *ppv = iface;
647 IUnknown_AddRef(iface);
648 return S_OK;
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)
666 IMoniker *pMoniker;
667 HRESULT hr;
669 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);
671 *ppv = NULL;
673 if (pUnk)
674 return CLASS_E_NOAGGREGATION;
676 hr = CreateAntiMoniker(&pMoniker);
677 if (FAILED(hr))
678 return hr;
680 hr = IMoniker_QueryInterface(pMoniker, riid, ppv);
682 if (FAILED(hr))
683 IMoniker_Release(pMoniker);
685 return hr;
688 static HRESULT WINAPI AntiMonikerCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
690 FIXME("(%d), stub!\n",fLock);
691 return S_OK;
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);