msvcp: Sync num_get<>::_Getifld.
[wine/multimedia.git] / dlls / ole32 / antimoniker.c
blob4c71fd4b2ce84739890eb0457b299690aa86ab91
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{
40 IMoniker IMoniker_iface;
41 IROTData IROTData_iface;
42 LONG ref;
43 IUnknown *pMarshal; /* custom marshaler */
44 } AntiMonikerImpl;
46 static inline AntiMonikerImpl *impl_from_IMoniker(IMoniker *iface)
48 return CONTAINING_RECORD(iface, AntiMonikerImpl, IMoniker_iface);
51 static inline AntiMonikerImpl *impl_from_IROTData(IROTData *iface)
53 return CONTAINING_RECORD(iface, AntiMonikerImpl, IROTData_iface);
57 /*******************************************************************************
58 * AntiMoniker_QueryInterface
59 *******************************************************************************/
60 static HRESULT WINAPI
61 AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
63 AntiMonikerImpl *This = impl_from_IMoniker(iface);
65 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
67 /* Perform a sanity check on the parameters.*/
68 if ( ppvObject==0 )
69 return E_INVALIDARG;
71 /* Initialize the return parameter */
72 *ppvObject = 0;
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))
79 *ppvObject = iface;
80 else if (IsEqualIID(&IID_IROTData, riid))
81 *ppvObject = &This->IROTData_iface;
82 else if (IsEqualIID(&IID_IMarshal, riid))
84 HRESULT hr = S_OK;
85 if (!This->pMarshal)
86 hr = MonikerMarshal_Create(iface, &This->pMarshal);
87 if (hr != S_OK)
88 return hr;
89 return IUnknown_QueryInterface(This->pMarshal, riid, ppvObject);
92 /* Check that we obtained an interface.*/
93 if ((*ppvObject)==0)
94 return E_NOINTERFACE;
96 /* always increase the reference count by one when it is successful */
97 IMoniker_AddRef(iface);
99 return S_OK;
102 /******************************************************************************
103 * AntiMoniker_AddRef
104 ******************************************************************************/
105 static ULONG WINAPI
106 AntiMonikerImpl_AddRef(IMoniker* iface)
108 AntiMonikerImpl *This = impl_from_IMoniker(iface);
110 TRACE("(%p)\n",This);
112 return InterlockedIncrement(&This->ref);
115 /******************************************************************************
116 * AntiMoniker_Release
117 ******************************************************************************/
118 static ULONG WINAPI
119 AntiMonikerImpl_Release(IMoniker* iface)
121 AntiMonikerImpl *This = impl_from_IMoniker(iface);
122 ULONG ref;
124 TRACE("(%p)\n",This);
126 ref = InterlockedDecrement(&This->ref);
128 /* destroy the object if there's no more reference on it */
129 if (ref == 0)
131 if (This->pMarshal) IUnknown_Release(This->pMarshal);
132 HeapFree(GetProcessHeap(),0,This);
135 return ref;
138 /******************************************************************************
139 * AntiMoniker_GetClassID
140 ******************************************************************************/
141 static HRESULT WINAPI
142 AntiMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
144 TRACE("(%p,%p)\n",iface,pClassID);
146 if (pClassID==NULL)
147 return E_POINTER;
149 *pClassID = CLSID_AntiMoniker;
151 return S_OK;
154 /******************************************************************************
155 * AntiMoniker_IsDirty
156 ******************************************************************************/
157 static HRESULT WINAPI
158 AntiMonikerImpl_IsDirty(IMoniker* iface)
160 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
161 method in the OLE-provided moniker interfaces always return S_FALSE because
162 their internal state never changes. */
164 TRACE("(%p)\n",iface);
166 return S_FALSE;
169 /******************************************************************************
170 * AntiMoniker_Load
171 ******************************************************************************/
172 static HRESULT WINAPI
173 AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
175 DWORD constant=1,dwbuffer;
176 HRESULT res;
178 /* data read by this function is only a DWORD constant (must be 1) ! */
179 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),NULL);
181 if (SUCCEEDED(res)&& dwbuffer!=constant)
182 return E_FAIL;
184 return res;
187 /******************************************************************************
188 * AntiMoniker_Save
189 ******************************************************************************/
190 static HRESULT WINAPI
191 AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
193 static const DWORD constant = 1;
194 /* data written by this function is only a DWORD constant set to 1 ! */
195 return IStream_Write(pStm,&constant,sizeof(constant),NULL);
198 /******************************************************************************
199 * AntiMoniker_GetSizeMax
201 * PARAMS
202 * pcbSize [out] Pointer to size of stream needed to save object
203 ******************************************************************************/
204 static HRESULT WINAPI
205 AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize)
207 TRACE("(%p,%p)\n",iface,pcbSize);
209 if (!pcbSize)
210 return E_POINTER;
212 /* for more details see AntiMonikerImpl_Save comments */
215 * Normally the sizemax must be sizeof DWORD, but
216 * I tested this function it usually return 16 bytes
217 * more than the number of bytes used by AntiMoniker::Save function
219 pcbSize->u.LowPart = sizeof(DWORD)+16;
221 pcbSize->u.HighPart=0;
223 return S_OK;
226 /******************************************************************************
227 * AntiMoniker_BindToObject
228 ******************************************************************************/
229 static HRESULT WINAPI
230 AntiMonikerImpl_BindToObject(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
231 REFIID riid, VOID** ppvResult)
233 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
234 return E_NOTIMPL;
237 /******************************************************************************
238 * AntiMoniker_BindToStorage
239 ******************************************************************************/
240 static HRESULT WINAPI
241 AntiMonikerImpl_BindToStorage(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
242 REFIID riid, VOID** ppvResult)
244 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
245 return E_NOTIMPL;
248 /******************************************************************************
249 * AntiMoniker_Reduce
250 ******************************************************************************/
251 static HRESULT WINAPI
252 AntiMonikerImpl_Reduce(IMoniker* iface, IBindCtx* pbc, DWORD dwReduceHowFar,
253 IMoniker** ppmkToLeft, IMoniker** ppmkReduced)
255 TRACE("(%p,%p,%d,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
257 if (ppmkReduced==NULL)
258 return E_POINTER;
260 AntiMonikerImpl_AddRef(iface);
262 *ppmkReduced=iface;
264 return MK_S_REDUCED_TO_SELF;
266 /******************************************************************************
267 * AntiMoniker_ComposeWith
268 ******************************************************************************/
269 static HRESULT WINAPI
270 AntiMonikerImpl_ComposeWith(IMoniker* iface, IMoniker* pmkRight,
271 BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite)
274 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
276 if ((ppmkComposite==NULL)||(pmkRight==NULL))
277 return E_POINTER;
279 *ppmkComposite=0;
281 if (fOnlyIfNotGeneric)
282 return MK_E_NEEDGENERIC;
283 else
284 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
287 /******************************************************************************
288 * AntiMoniker_Enum
289 ******************************************************************************/
290 static HRESULT WINAPI
291 AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
293 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
295 if (ppenumMoniker == NULL)
296 return E_POINTER;
298 *ppenumMoniker = NULL;
300 return S_OK;
303 /******************************************************************************
304 * AntiMoniker_IsEqual
305 ******************************************************************************/
306 static HRESULT WINAPI
307 AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
309 DWORD mkSys;
311 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
313 if (pmkOtherMoniker==NULL)
314 return S_FALSE;
316 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
318 if (mkSys==MKSYS_ANTIMONIKER)
319 return S_OK;
320 else
321 return S_FALSE;
324 /******************************************************************************
325 * AntiMoniker_Hash
326 ******************************************************************************/
327 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
329 if (pdwHash==NULL)
330 return E_POINTER;
332 *pdwHash = 0x80000001;
334 return S_OK;
337 /******************************************************************************
338 * AntiMoniker_IsRunning
339 ******************************************************************************/
340 static HRESULT WINAPI
341 AntiMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
342 IMoniker* pmkNewlyRunning)
344 IRunningObjectTable* rot;
345 HRESULT res;
347 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
349 if (pbc==NULL)
350 return E_INVALIDARG;
352 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
354 if (FAILED(res))
355 return res;
357 res = IRunningObjectTable_IsRunning(rot,iface);
359 IRunningObjectTable_Release(rot);
361 return res;
364 /******************************************************************************
365 * AntiMoniker_GetTimeOfLastChange
366 ******************************************************************************/
367 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
368 IBindCtx* pbc,
369 IMoniker* pmkToLeft,
370 FILETIME* pAntiTime)
372 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
373 return E_NOTIMPL;
376 /******************************************************************************
377 * AntiMoniker_Inverse
378 ******************************************************************************/
379 static HRESULT WINAPI
380 AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
382 TRACE("(%p,%p)\n",iface,ppmk);
384 if (ppmk==NULL)
385 return E_POINTER;
387 *ppmk=0;
389 return MK_E_NOINVERSE;
392 /******************************************************************************
393 * AntiMoniker_CommonPrefixWith
394 ******************************************************************************/
395 static HRESULT WINAPI
396 AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
398 DWORD mkSys;
400 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
402 if(mkSys==MKSYS_ANTIMONIKER){
404 IMoniker_AddRef(iface);
406 *ppmkPrefix=iface;
408 IMoniker_AddRef(iface);
410 return MK_S_US;
412 else
413 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
416 /******************************************************************************
417 * AntiMoniker_RelativePathTo
418 ******************************************************************************/
419 static HRESULT WINAPI
420 AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
422 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
424 if (ppmkRelPath==NULL)
425 return E_POINTER;
427 IMoniker_AddRef(pmOther);
429 *ppmkRelPath=pmOther;
431 return MK_S_HIM;
434 /******************************************************************************
435 * AntiMoniker_GetDisplayName
436 ******************************************************************************/
437 static HRESULT WINAPI
438 AntiMonikerImpl_GetDisplayName(IMoniker* iface, IBindCtx* pbc,
439 IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName)
441 static const WCHAR back[]={'\\','.','.',0};
443 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
445 if (ppszDisplayName==NULL)
446 return E_POINTER;
448 if (pmkToLeft!=NULL){
449 FIXME("() pmkToLeft!=NULL not implemented\n");
450 return E_NOTIMPL;
453 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
455 if (*ppszDisplayName==NULL)
456 return E_OUTOFMEMORY;
458 lstrcpyW(*ppszDisplayName,back);
460 return S_OK;
463 /******************************************************************************
464 * AntiMoniker_ParseDisplayName
465 ******************************************************************************/
466 static HRESULT WINAPI
467 AntiMonikerImpl_ParseDisplayName(IMoniker* iface, IBindCtx* pbc,
468 IMoniker* pmkToLeft, LPOLESTR pszDisplayName,
469 ULONG* pchEaten, IMoniker** ppmkOut)
471 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
472 return E_NOTIMPL;
475 /******************************************************************************
476 * AntiMoniker_IsSystemMoniker
477 ******************************************************************************/
478 static HRESULT WINAPI
479 AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
481 TRACE("(%p,%p)\n",iface,pwdMksys);
483 if (!pwdMksys)
484 return E_POINTER;
486 (*pwdMksys)=MKSYS_ANTIMONIKER;
488 return S_OK;
491 /*******************************************************************************
492 * AntiMonikerIROTData_QueryInterface
493 *******************************************************************************/
494 static HRESULT WINAPI
495 AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
497 AntiMonikerImpl *This = impl_from_IROTData(iface);
499 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
501 return AntiMonikerImpl_QueryInterface(&This->IMoniker_iface, riid, ppvObject);
504 /***********************************************************************
505 * AntiMonikerIROTData_AddRef
507 static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
509 AntiMonikerImpl *This = impl_from_IROTData(iface);
511 TRACE("(%p)\n",iface);
513 return AntiMonikerImpl_AddRef(&This->IMoniker_iface);
516 /***********************************************************************
517 * AntiMonikerIROTData_Release
519 static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
521 AntiMonikerImpl *This = impl_from_IROTData(iface);
523 TRACE("(%p)\n",iface);
525 return AntiMonikerImpl_Release(&This->IMoniker_iface);
528 /******************************************************************************
529 * AntiMonikerIROTData_GetComparisonData
530 ******************************************************************************/
531 static HRESULT WINAPI
532 AntiMonikerROTDataImpl_GetComparisonData(IROTData* iface, BYTE* pbData,
533 ULONG cbMax, ULONG* pcbData)
535 DWORD constant = 1;
537 TRACE("(%p, %u, %p)\n", pbData, cbMax, pcbData);
539 *pcbData = sizeof(CLSID) + sizeof(DWORD);
540 if (cbMax < *pcbData)
541 return E_OUTOFMEMORY;
543 memcpy(pbData, &CLSID_AntiMoniker, sizeof(CLSID));
544 memcpy(pbData+sizeof(CLSID), &constant, sizeof(DWORD));
546 return S_OK;
549 /********************************************************************************/
550 /* Virtual function table for the AntiMonikerImpl class which include IPersist,*/
551 /* IPersistStream and IMoniker functions. */
552 static const IMonikerVtbl VT_AntiMonikerImpl =
554 AntiMonikerImpl_QueryInterface,
555 AntiMonikerImpl_AddRef,
556 AntiMonikerImpl_Release,
557 AntiMonikerImpl_GetClassID,
558 AntiMonikerImpl_IsDirty,
559 AntiMonikerImpl_Load,
560 AntiMonikerImpl_Save,
561 AntiMonikerImpl_GetSizeMax,
562 AntiMonikerImpl_BindToObject,
563 AntiMonikerImpl_BindToStorage,
564 AntiMonikerImpl_Reduce,
565 AntiMonikerImpl_ComposeWith,
566 AntiMonikerImpl_Enum,
567 AntiMonikerImpl_IsEqual,
568 AntiMonikerImpl_Hash,
569 AntiMonikerImpl_IsRunning,
570 AntiMonikerImpl_GetTimeOfLastChange,
571 AntiMonikerImpl_Inverse,
572 AntiMonikerImpl_CommonPrefixWith,
573 AntiMonikerImpl_RelativePathTo,
574 AntiMonikerImpl_GetDisplayName,
575 AntiMonikerImpl_ParseDisplayName,
576 AntiMonikerImpl_IsSystemMoniker
579 /********************************************************************************/
580 /* Virtual function table for the IROTData class. */
581 static const IROTDataVtbl VT_ROTDataImpl =
583 AntiMonikerROTDataImpl_QueryInterface,
584 AntiMonikerROTDataImpl_AddRef,
585 AntiMonikerROTDataImpl_Release,
586 AntiMonikerROTDataImpl_GetComparisonData
589 /******************************************************************************
590 * AntiMoniker_Construct (local function)
591 *******************************************************************************/
592 static HRESULT AntiMonikerImpl_Construct(AntiMonikerImpl* This)
595 TRACE("(%p)\n",This);
597 /* Initialize the virtual function table. */
598 This->IMoniker_iface.lpVtbl = &VT_AntiMonikerImpl;
599 This->IROTData_iface.lpVtbl = &VT_ROTDataImpl;
600 This->ref = 0;
601 This->pMarshal = NULL;
603 return S_OK;
606 /******************************************************************************
607 * CreateAntiMoniker [OLE32.@]
608 ******************************************************************************/
609 HRESULT WINAPI CreateAntiMoniker(IMoniker **ppmk)
611 AntiMonikerImpl* newAntiMoniker;
612 HRESULT hr;
614 TRACE("(%p)\n",ppmk);
616 newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));
618 if (newAntiMoniker == 0)
619 return STG_E_INSUFFICIENTMEMORY;
621 hr = AntiMonikerImpl_Construct(newAntiMoniker);
622 if (FAILED(hr))
624 HeapFree(GetProcessHeap(),0,newAntiMoniker);
625 return hr;
628 return AntiMonikerImpl_QueryInterface(&newAntiMoniker->IMoniker_iface, &IID_IMoniker,
629 (void**)ppmk);
632 static HRESULT WINAPI AntiMonikerCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
634 *ppv = NULL;
635 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
637 *ppv = iface;
638 IClassFactory_AddRef(iface);
639 return S_OK;
641 return E_NOINTERFACE;
644 static ULONG WINAPI AntiMonikerCF_AddRef(LPCLASSFACTORY iface)
646 return 2; /* non-heap based object */
649 static ULONG WINAPI AntiMonikerCF_Release(LPCLASSFACTORY iface)
651 return 1; /* non-heap based object */
654 static HRESULT WINAPI AntiMonikerCF_CreateInstance(LPCLASSFACTORY iface,
655 LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
657 IMoniker *pMoniker;
658 HRESULT hr;
660 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);
662 *ppv = NULL;
664 if (pUnk)
665 return CLASS_E_NOAGGREGATION;
667 hr = CreateAntiMoniker(&pMoniker);
668 if (FAILED(hr))
669 return hr;
671 hr = IMoniker_QueryInterface(pMoniker, riid, ppv);
673 if (FAILED(hr))
674 IMoniker_Release(pMoniker);
676 return hr;
679 static HRESULT WINAPI AntiMonikerCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
681 FIXME("(%d), stub!\n",fLock);
682 return S_OK;
685 static const IClassFactoryVtbl AntiMonikerCFVtbl =
687 AntiMonikerCF_QueryInterface,
688 AntiMonikerCF_AddRef,
689 AntiMonikerCF_Release,
690 AntiMonikerCF_CreateInstance,
691 AntiMonikerCF_LockServer
693 static const IClassFactoryVtbl *AntiMonikerCF = &AntiMonikerCFVtbl;
695 HRESULT AntiMonikerCF_Create(REFIID riid, LPVOID *ppv)
697 return IClassFactory_QueryInterface((IClassFactory *)&AntiMonikerCF, riid, ppv);