Added support for WODM_BREAKLOOP message.
[wine.git] / dlls / ole32 / antimoniker.c
blobdcb41e6a8d0251f4fc8755d0e6501e6bd10762d8
1 /***************************************************************************************
2 * AntiMonikers implementation
4 * Copyright 1999 Noomen Hamza
5 ***************************************************************************************/
7 #include <assert.h>
8 #include "winbase.h"
9 #include "winerror.h"
10 #include "wine/obj_moniker.h"
11 #include "debugtools.h"
13 DEFAULT_DEBUG_CHANNEL(ole)
15 /* AntiMoniker data structure */
16 typedef struct AntiMonikerImpl{
18 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
20 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
21 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
23 ICOM_VTABLE(IROTData)* lpvtbl2; /* VTable relative to the IROTData interface.*/
25 ULONG ref; /* reference counter for this object */
27 } AntiMonikerImpl;
29 /********************************************************************************/
30 /* AntiMoniker prototype functions : */
32 /* IUnknown prototype functions */
33 static HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
34 static ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface);
35 static ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface);
37 /* IPersist prototype functions */
38 static HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
40 /* IPersistStream prototype functions */
41 static HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface);
42 static HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface, IStream* pStm);
43 static HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
44 static HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
46 /* IMoniker prototype functions */
47 static HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
48 static HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
49 static HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
50 static HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
51 static HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
52 static HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
53 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
54 static HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
55 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pAntiTime);
56 static HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
57 static HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
58 static HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
59 static HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
60 static HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
61 static HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
63 /********************************************************************************/
64 /* IROTData prototype functions */
66 /* IUnknown prototype functions */
67 static HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
68 static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData* iface);
69 static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface);
71 /* IROTData prototype function */
72 static HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
74 /* Local function used by AntiMoniker implementation */
75 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* iface);
76 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* iface);
78 /********************************************************************************/
79 /* Virtual function table for the AntiMonikerImpl class witch include Ipersist,*/
80 /* IPersistStream and IMoniker functions. */
81 static ICOM_VTABLE(IMoniker) VT_AntiMonikerImpl =
83 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
84 AntiMonikerImpl_QueryInterface,
85 AntiMonikerImpl_AddRef,
86 AntiMonikerImpl_Release,
87 AntiMonikerImpl_GetClassID,
88 AntiMonikerImpl_IsDirty,
89 AntiMonikerImpl_Load,
90 AntiMonikerImpl_Save,
91 AntiMonikerImpl_GetSizeMax,
92 AntiMonikerImpl_BindToObject,
93 AntiMonikerImpl_BindToStorage,
94 AntiMonikerImpl_Reduce,
95 AntiMonikerImpl_ComposeWith,
96 AntiMonikerImpl_Enum,
97 AntiMonikerImpl_IsEqual,
98 AntiMonikerImpl_Hash,
99 AntiMonikerImpl_IsRunning,
100 AntiMonikerImpl_GetTimeOfLastChange,
101 AntiMonikerImpl_Inverse,
102 AntiMonikerImpl_CommonPrefixWith,
103 AntiMonikerImpl_RelativePathTo,
104 AntiMonikerImpl_GetDisplayName,
105 AntiMonikerImpl_ParseDisplayName,
106 AntiMonikerImpl_IsSystemMoniker
109 /********************************************************************************/
110 /* Virtual function table for the IROTData class. */
111 static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
113 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
114 AntiMonikerROTDataImpl_QueryInterface,
115 AntiMonikerROTDataImpl_AddRef,
116 AntiMonikerROTDataImpl_Release,
117 AntiMonikerROTDataImpl_GetComparaisonData
120 /*******************************************************************************
121 * AntiMoniker_QueryInterface
122 *******************************************************************************/
123 HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
125 ICOM_THIS(AntiMonikerImpl,iface);
127 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
129 /* Perform a sanity check on the parameters.*/
130 if ( (This==0) || (ppvObject==0) )
131 return E_INVALIDARG;
133 /* Initialize the return parameter */
134 *ppvObject = 0;
136 /* Compare the riid with the interface IDs implemented by this object.*/
137 if (IsEqualIID(&IID_IUnknown, riid) ||
138 IsEqualIID(&IID_IPersist, riid) ||
139 IsEqualIID(&IID_IPersistStream, riid) ||
140 IsEqualIID(&IID_IMoniker, riid)
142 *ppvObject = iface;
143 else if (IsEqualIID(&IID_IROTData, riid))
144 *ppvObject = (IROTData*)&(This->lpvtbl2);
146 /* Check that we obtained an interface.*/
147 if ((*ppvObject)==0)
148 return E_NOINTERFACE;
150 /* Query Interface always increases the reference count by one when it is successful */
151 AntiMonikerImpl_AddRef(iface);
153 return S_OK;
156 /******************************************************************************
157 * AntiMoniker_AddRef
158 ******************************************************************************/
159 ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface)
161 ICOM_THIS(AntiMonikerImpl,iface);
163 TRACE("(%p)\n",This);
165 return ++(This->ref);
168 /******************************************************************************
169 * AntiMoniker_Release
170 ******************************************************************************/
171 ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface)
173 ICOM_THIS(AntiMonikerImpl,iface);
175 TRACE("(%p)\n",This);
177 This->ref--;
179 /* destroy the object if there's no more reference on it */
180 if (This->ref==0){
182 AntiMonikerImpl_Destroy(This);
184 return 0;
186 return This->ref;;
189 /******************************************************************************
190 * AntiMoniker_GetClassID
191 ******************************************************************************/
192 HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
194 TRACE("(%p,%p),stub!\n",iface,pClassID);
196 if (pClassID==NULL)
197 return E_POINTER;
199 *pClassID = CLSID_AntiMoniker;
201 return S_OK;
204 /******************************************************************************
205 * AntiMoniker_IsDirty
206 ******************************************************************************/
207 HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface)
209 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
210 method in the OLE-provided moniker interfaces always return S_FALSE because
211 their internal state never changes. */
213 TRACE("(%p)\n",iface);
215 return S_FALSE;
218 /******************************************************************************
219 * AntiMoniker_Load
220 ******************************************************************************/
221 HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
223 DWORD constant=1,dwbuffer;
224 HRESULT res;
226 /* data read by this function is only a DWORD constant (must be 1) ! */
227 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),NULL);
229 if (SUCCEEDED(res)&& dwbuffer!=constant)
230 return E_FAIL;
232 return res;
235 /******************************************************************************
236 * AntiMoniker_Save
237 ******************************************************************************/
238 HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
240 DWORD constant=1;
241 HRESULT res;
243 /* data writen by this function is only a DWORD constant seted to 1 ! */
244 res=IStream_Write(pStm,&constant,sizeof(constant),NULL);
246 return res;
249 /******************************************************************************
250 * AntiMoniker_GetSizeMax
251 ******************************************************************************/
252 HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface,
253 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
255 TRACE("(%p,%p)\n",iface,pcbSize);
257 if (pcbSize!=NULL)
258 return E_POINTER;
260 /* for more details see AntiMonikerImpl_Save coments */
262 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
263 /* more than the number of bytes used by AntiMoniker::Save function */
264 pcbSize->s.LowPart = sizeof(DWORD)+16;
266 pcbSize->s.HighPart=0;
268 return S_OK;
271 /******************************************************************************
272 * AntiMoniker_Construct (local function)
273 *******************************************************************************/
274 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* This)
277 TRACE("(%p)\n",This);
279 /* Initialize the virtual fgunction table. */
280 This->lpvtbl1 = &VT_AntiMonikerImpl;
281 This->lpvtbl2 = &VT_ROTDataImpl;
282 This->ref = 0;
284 return S_OK;
287 /******************************************************************************
288 * AntiMoniker_Destroy (local function)
289 *******************************************************************************/
290 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* This)
292 TRACE("(%p)\n",This);
294 return HeapFree(GetProcessHeap(),0,This);
297 /******************************************************************************
298 * AntiMoniker_BindToObject
299 ******************************************************************************/
300 HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,
301 IBindCtx* pbc,
302 IMoniker* pmkToLeft,
303 REFIID riid,
304 VOID** ppvResult)
306 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
307 return E_NOTIMPL;
310 /******************************************************************************
311 * AntiMoniker_BindToStorage
312 ******************************************************************************/
313 HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,
314 IBindCtx* pbc,
315 IMoniker* pmkToLeft,
316 REFIID riid,
317 VOID** ppvResult)
319 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
320 return E_NOTIMPL;
323 /******************************************************************************
324 * AntiMoniker_Reduce
325 ******************************************************************************/
326 HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,
327 IBindCtx* pbc,
328 DWORD dwReduceHowFar,
329 IMoniker** ppmkToLeft,
330 IMoniker** ppmkReduced)
332 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
334 if (ppmkReduced==NULL)
335 return E_POINTER;
337 AntiMonikerImpl_AddRef(iface);
339 *ppmkReduced=iface;
341 return MK_S_REDUCED_TO_SELF;
343 /******************************************************************************
344 * AntiMoniker_ComposeWith
345 ******************************************************************************/
346 HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,
347 IMoniker* pmkRight,
348 BOOL fOnlyIfNotGeneric,
349 IMoniker** ppmkComposite)
352 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
354 if ((ppmkComposite==NULL)||(pmkRight==NULL))
355 return E_POINTER;
357 *ppmkComposite=0;
359 if (fOnlyIfNotGeneric)
360 return MK_E_NEEDGENERIC;
361 else
362 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
365 /******************************************************************************
366 * AntiMoniker_Enum
367 ******************************************************************************/
368 HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
370 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
372 if (ppenumMoniker == NULL)
373 return E_POINTER;
375 *ppenumMoniker = NULL;
377 return S_OK;
380 /******************************************************************************
381 * AntiMoniker_IsEqual
382 ******************************************************************************/
383 HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
385 DWORD mkSys;
387 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
389 if (pmkOtherMoniker==NULL)
390 return S_FALSE;
392 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
394 if (mkSys==MKSYS_ANTIMONIKER)
395 return S_OK;
396 else
397 return S_FALSE;
400 /******************************************************************************
401 * AntiMoniker_Hash
402 ******************************************************************************/
403 HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
405 if (pdwHash==NULL)
406 return E_POINTER;
408 *pdwHash=0;
410 return S_OK;
413 /******************************************************************************
414 * AntiMoniker_IsRunning
415 ******************************************************************************/
416 HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,
417 IBindCtx* pbc,
418 IMoniker* pmkToLeft,
419 IMoniker* pmkNewlyRunning)
421 IRunningObjectTable* rot;
422 HRESULT res;
424 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
426 if (pbc==NULL)
427 return E_INVALIDARG;
429 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
431 if (FAILED(res))
432 return res;
434 res = IRunningObjectTable_IsRunning(rot,iface);
436 IRunningObjectTable_Release(rot);
438 return res;
441 /******************************************************************************
442 * AntiMoniker_GetTimeOfLastChange
443 ******************************************************************************/
444 HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
445 IBindCtx* pbc,
446 IMoniker* pmkToLeft,
447 FILETIME* pAntiTime)
449 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
450 return E_NOTIMPL;
453 /******************************************************************************
454 * AntiMoniker_Inverse
455 ******************************************************************************/
456 HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
458 TRACE("(%p,%p)\n",iface,ppmk);
460 if (ppmk==NULL)
461 return E_POINTER;
463 *ppmk=0;
465 return MK_E_NOINVERSE;
468 /******************************************************************************
469 * AntiMoniker_CommonPrefixWith
470 ******************************************************************************/
471 HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
473 DWORD mkSys;
475 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
477 if(mkSys==MKSYS_ITEMMONIKER){
479 IMoniker_AddRef(iface);
481 *ppmkPrefix=iface;
483 IMoniker_AddRef(iface);
485 return MK_S_US;
487 else
488 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
491 /******************************************************************************
492 * AntiMoniker_RelativePathTo
493 ******************************************************************************/
494 HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
496 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
498 if (ppmkRelPath==NULL)
499 return E_POINTER;
501 IMoniker_AddRef(pmOther);
503 *ppmkRelPath=pmOther;
505 return MK_S_HIM;
508 /******************************************************************************
509 * AntiMoniker_GetDisplayName
510 ******************************************************************************/
511 HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,
512 IBindCtx* pbc,
513 IMoniker* pmkToLeft,
514 LPOLESTR *ppszDisplayName)
516 WCHAR back[]={'\\','.','.',0};
518 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
520 if (ppszDisplayName==NULL)
521 return E_POINTER;
523 if (pmkToLeft!=NULL){
524 FIXME("() pmkToLeft!=NULL not implemented \n");
525 return E_NOTIMPL;
528 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
530 if (*ppszDisplayName==NULL)
531 return E_OUTOFMEMORY;
533 lstrcpyW(*ppszDisplayName,back);
535 return S_OK;
538 /******************************************************************************
539 * AntiMoniker_ParseDisplayName
540 ******************************************************************************/
541 HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,
542 IBindCtx* pbc,
543 IMoniker* pmkToLeft,
544 LPOLESTR pszDisplayName,
545 ULONG* pchEaten,
546 IMoniker** ppmkOut)
548 TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
549 return E_NOTIMPL;
552 /******************************************************************************
553 * AntiMoniker_IsSystemMonker
554 ******************************************************************************/
555 HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
557 TRACE("(%p,%p)\n",iface,pwdMksys);
559 if (!pwdMksys)
560 return E_POINTER;
562 (*pwdMksys)=MKSYS_ANTIMONIKER;
564 return S_OK;
567 /*******************************************************************************
568 * AntiMonikerIROTData_QueryInterface
569 *******************************************************************************/
570 HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
573 ICOM_THIS_From_IROTData(IMoniker, iface);
575 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
577 return AntiMonikerImpl_QueryInterface(This, riid, ppvObject);
580 /***********************************************************************
581 * AntiMonikerIROTData_AddRef
583 ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
585 ICOM_THIS_From_IROTData(IMoniker, iface);
587 TRACE("(%p)\n",iface);
589 return AntiMonikerImpl_AddRef(This);
592 /***********************************************************************
593 * AntiMonikerIROTData_Release
595 ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
597 ICOM_THIS_From_IROTData(IMoniker, iface);
599 TRACE("(%p)\n",iface);
601 return AntiMonikerImpl_Release(This);
604 /******************************************************************************
605 * AntiMonikerIROTData_GetComparaisonData
606 ******************************************************************************/
607 HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
608 BYTE* pbData,
609 ULONG cbMax,
610 ULONG* pcbData)
612 FIXME("(),stub!\n");
613 return E_NOTIMPL;
616 /******************************************************************************
617 * CreateAntiMoniker [OLE.55]
618 ******************************************************************************/
619 HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
621 AntiMonikerImpl* newAntiMoniker = 0;
622 HRESULT hr = S_OK;
623 IID riid=IID_IMoniker;
625 TRACE("(%p)\n",ppmk);
627 newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));
629 if (newAntiMoniker == 0)
630 return STG_E_INSUFFICIENTMEMORY;
632 hr = AntiMonikerImpl_Construct(newAntiMoniker);
634 if (FAILED(hr)){
636 HeapFree(GetProcessHeap(),0,newAntiMoniker);
637 return hr;
640 hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk);
642 return hr;