Test for static was reversed.
[wine.git] / ole / antimoniker.c
blob9d537c36d1fe5af7f506e9d3e0901cd332d63792
1 /***************************************************************************************
2 * AntiMonikers implementation
4 * Copyright 1999 Noomen Hamza
5 ***************************************************************************************/
7 #include <assert.h>
8 #include "winerror.h"
9 #include "debug.h"
10 #include "heap.h"
11 #include "winuser.h"
12 #include "file.h"
13 #include "winreg.h"
14 #include "objbase.h"
15 #include "wine/obj_inplace.h"
17 DEFAULT_DEBUG_CHANNEL(ole)
19 /* AntiMoniker data structure */
20 typedef struct AntiMonikerImpl{
22 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
24 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
25 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
27 ICOM_VTABLE(IROTData)* lpvtbl2; /* VTable relative to the IROTData interface.*/
29 ULONG ref; /* reference counter for this object */
31 } AntiMonikerImpl;
33 /********************************************************************************/
34 /* AntiMoniker prototype functions : */
36 /* IUnknown prototype functions */
37 static HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
38 static ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface);
39 static ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface);
41 /* IPersist prototype functions */
42 static HRESULT WINAPI AntiMonikerImpl_GetClassID(const IMoniker* iface, CLSID *pClassID);
44 /* IPersistStream prototype functions */
45 static HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface);
46 static HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface, IStream* pStm);
47 static HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
48 static HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
50 /* IMoniker prototype functions */
51 static HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
52 static HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
53 static HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
54 static HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
55 static HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
56 static HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
57 static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
58 static HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
59 static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pAntiTime);
60 static HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
61 static HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
62 static HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
63 static HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
64 static HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
65 static HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
67 /********************************************************************************/
68 /* IROTData prototype functions */
70 /* IUnknown prototype functions */
71 static HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
72 static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData* iface);
73 static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface);
75 /* IROTData prototype function */
76 static HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
78 /* Local function used by AntiMoniker implementation */
79 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* iface);
80 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* iface);
82 /********************************************************************************/
83 /* Virtual function table for the AntiMonikerImpl class witch include Ipersist,*/
84 /* IPersistStream and IMoniker functions. */
85 static ICOM_VTABLE(IMoniker) VT_AntiMonikerImpl =
87 AntiMonikerImpl_QueryInterface,
88 AntiMonikerImpl_AddRef,
89 AntiMonikerImpl_Release,
90 AntiMonikerImpl_GetClassID,
91 AntiMonikerImpl_IsDirty,
92 AntiMonikerImpl_Load,
93 AntiMonikerImpl_Save,
94 AntiMonikerImpl_GetSizeMax,
95 AntiMonikerImpl_BindToObject,
96 AntiMonikerImpl_BindToStorage,
97 AntiMonikerImpl_Reduce,
98 AntiMonikerImpl_ComposeWith,
99 AntiMonikerImpl_Enum,
100 AntiMonikerImpl_IsEqual,
101 AntiMonikerImpl_Hash,
102 AntiMonikerImpl_IsRunning,
103 AntiMonikerImpl_GetTimeOfLastChange,
104 AntiMonikerImpl_Inverse,
105 AntiMonikerImpl_CommonPrefixWith,
106 AntiMonikerImpl_RelativePathTo,
107 AntiMonikerImpl_GetDisplayName,
108 AntiMonikerImpl_ParseDisplayName,
109 AntiMonikerImpl_IsSystemMoniker
112 /********************************************************************************/
113 /* Virtual function table for the IROTData class. */
114 static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
116 AntiMonikerROTDataImpl_QueryInterface,
117 AntiMonikerROTDataImpl_AddRef,
118 AntiMonikerROTDataImpl_Release,
119 AntiMonikerROTDataImpl_GetComparaisonData
122 /*******************************************************************************
123 * AntiMoniker_QueryInterface
124 *******************************************************************************/
125 HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
127 ICOM_THIS(AntiMonikerImpl,iface);
129 TRACE(ole,"(%p,%p,%p)\n",This,riid,ppvObject);
131 /* Perform a sanity check on the parameters.*/
132 if ( (This==0) || (ppvObject==0) )
133 return E_INVALIDARG;
135 /* Initialize the return parameter */
136 *ppvObject = 0;
138 /* Compare the riid with the interface IDs implemented by this object.*/
139 if (IsEqualIID(&IID_IUnknown, riid) ||
140 IsEqualIID(&IID_IPersist, riid) ||
141 IsEqualIID(&IID_IPersistStream, riid) ||
142 IsEqualIID(&IID_IMoniker, riid)
144 *ppvObject = iface;
145 else if (IsEqualIID(&IID_IROTData, riid))
146 *ppvObject = (IROTData*)&(This->lpvtbl2);
148 /* Check that we obtained an interface.*/
149 if ((*ppvObject)==0)
150 return E_NOINTERFACE;
152 /* Query Interface always increases the reference count by one when it is successful */
153 AntiMonikerImpl_AddRef(iface);
155 return S_OK;
158 /******************************************************************************
159 * AntiMoniker_AddRef
160 ******************************************************************************/
161 ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface)
163 ICOM_THIS(AntiMonikerImpl,iface);
165 TRACE(ole,"(%p)\n",This);
167 return ++(This->ref);
170 /******************************************************************************
171 * AntiMoniker_Release
172 ******************************************************************************/
173 ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface)
175 ICOM_THIS(AntiMonikerImpl,iface);
177 TRACE(ole,"(%p)\n",This);
179 This->ref--;
181 /* destroy the object if there's no more reference on it */
182 if (This->ref==0){
184 AntiMonikerImpl_Destroy(This);
186 return 0;
188 return This->ref;;
191 /******************************************************************************
192 * AntiMoniker_GetClassID
193 ******************************************************************************/
194 HRESULT WINAPI AntiMonikerImpl_GetClassID(const IMoniker* iface,CLSID *pClassID)
196 TRACE(ole,"(%p,%p),stub!\n",iface,pClassID);
198 if (pClassID==NULL)
199 return E_POINTER;
201 *pClassID = CLSID_AntiMoniker;
203 return S_OK;
206 /******************************************************************************
207 * AntiMoniker_IsDirty
208 ******************************************************************************/
209 HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface)
211 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
212 method in the OLE-provided moniker interfaces always return S_FALSE because
213 their internal state never changes. */
215 TRACE(ole,"(%p)\n",iface);
217 return S_FALSE;
220 /******************************************************************************
221 * AntiMoniker_Load
222 ******************************************************************************/
223 HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
225 DWORD constant=1,dwbuffer;
226 HRESULT res;
228 /* data read by this function is only a DWORD constant (must be 1) ! */
229 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),NULL);
231 if (SUCCEEDED(res)&& dwbuffer!=constant)
232 return E_FAIL;
234 return res;
237 /******************************************************************************
238 * AntiMoniker_Save
239 ******************************************************************************/
240 HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
242 DWORD constant=1;
243 HRESULT res;
245 /* data writen by this function is only a DWORD constant seted to 1 ! */
246 res=IStream_Write(pStm,&constant,sizeof(constant),NULL);
248 return res;
251 /******************************************************************************
252 * AntiMoniker_GetSizeMax
253 ******************************************************************************/
254 HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface,
255 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
257 TRACE(ole,"(%p,%p)\n",iface,pcbSize);
259 if (pcbSize!=NULL)
260 return E_POINTER;
262 /* for more details see AntiMonikerImpl_Save coments */
264 /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */
265 /* more than the number of bytes used by AntiMoniker::Save function */
266 pcbSize->LowPart = sizeof(DWORD)+16;
268 pcbSize->HighPart=0;
270 return S_OK;
273 /******************************************************************************
274 * AntiMoniker_Construct (local function)
275 *******************************************************************************/
276 HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* This)
279 TRACE(ole,"(%p)\n",This);
281 /* Initialize the virtual fgunction table. */
282 This->lpvtbl1 = &VT_AntiMonikerImpl;
283 This->lpvtbl2 = &VT_ROTDataImpl;
284 This->ref = 0;
286 return S_OK;
289 /******************************************************************************
290 * AntiMoniker_Destroy (local function)
291 *******************************************************************************/
292 HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* This)
294 TRACE(ole,"(%p)\n",This);
296 return HeapFree(GetProcessHeap(),0,This);
299 /******************************************************************************
300 * AntiMoniker_BindToObject
301 ******************************************************************************/
302 HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,
303 IBindCtx* pbc,
304 IMoniker* pmkToLeft,
305 REFIID riid,
306 VOID** ppvResult)
308 TRACE(ole,"(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
309 return E_NOTIMPL;
312 /******************************************************************************
313 * AntiMoniker_BindToStorage
314 ******************************************************************************/
315 HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,
316 IBindCtx* pbc,
317 IMoniker* pmkToLeft,
318 REFIID riid,
319 VOID** ppvResult)
321 TRACE(ole,"(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
322 return E_NOTIMPL;
325 /******************************************************************************
326 * AntiMoniker_Reduce
327 ******************************************************************************/
328 HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,
329 IBindCtx* pbc,
330 DWORD dwReduceHowFar,
331 IMoniker** ppmkToLeft,
332 IMoniker** ppmkReduced)
334 TRACE(ole,"(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
336 if (ppmkReduced==NULL)
337 return E_POINTER;
339 AntiMonikerImpl_AddRef(iface);
341 *ppmkReduced=iface;
343 return MK_S_REDUCED_TO_SELF;
345 /******************************************************************************
346 * AntiMoniker_ComposeWith
347 ******************************************************************************/
348 HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,
349 IMoniker* pmkRight,
350 BOOL fOnlyIfNotGeneric,
351 IMoniker** ppmkComposite)
354 TRACE(ole,"(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
356 if ((ppmkComposite==NULL)||(pmkRight==NULL))
357 return E_POINTER;
359 *ppmkComposite=0;
361 if (fOnlyIfNotGeneric)
362 return MK_E_NEEDGENERIC;
363 else
364 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
367 /******************************************************************************
368 * AntiMoniker_Enum
369 ******************************************************************************/
370 HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
372 TRACE(ole,"(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
374 if (ppenumMoniker == NULL)
375 return E_POINTER;
377 *ppenumMoniker = NULL;
379 return S_OK;
382 /******************************************************************************
383 * AntiMoniker_IsEqual
384 ******************************************************************************/
385 HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
387 DWORD mkSys;
389 TRACE(ole,"(%p,%p)\n",iface,pmkOtherMoniker);
391 if (pmkOtherMoniker==NULL)
392 return S_FALSE;
394 IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);
396 if (mkSys==MKSYS_ANTIMONIKER)
397 return S_OK;
398 else
399 return S_FALSE;
402 /******************************************************************************
403 * AntiMoniker_Hash
404 ******************************************************************************/
405 HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
407 if (pdwHash==NULL)
408 return E_POINTER;
410 *pdwHash=0;
412 return S_OK;
415 /******************************************************************************
416 * AntiMoniker_IsRunning
417 ******************************************************************************/
418 HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,
419 IBindCtx* pbc,
420 IMoniker* pmkToLeft,
421 IMoniker* pmkNewlyRunning)
423 IRunningObjectTable* rot;
424 HRESULT res;
426 TRACE(ole,"(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
428 if (pbc==NULL)
429 return E_INVALIDARG;
431 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
433 if (FAILED(res))
434 return res;
436 res = IRunningObjectTable_IsRunning(rot,iface);
438 IRunningObjectTable_Release(rot);
440 return res;
443 /******************************************************************************
444 * AntiMoniker_GetTimeOfLastChange
445 ******************************************************************************/
446 HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
447 IBindCtx* pbc,
448 IMoniker* pmkToLeft,
449 FILETIME* pAntiTime)
451 TRACE(ole,"(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
452 return E_NOTIMPL;
455 /******************************************************************************
456 * AntiMoniker_Inverse
457 ******************************************************************************/
458 HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
460 TRACE(ole,"(%p,%p)\n",iface,ppmk);
462 if (ppmk==NULL)
463 return E_POINTER;
465 *ppmk=0;
467 return MK_E_NOINVERSE;
470 /******************************************************************************
471 * AntiMoniker_CommonPrefixWith
472 ******************************************************************************/
473 HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
475 DWORD mkSys;
477 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
479 if(mkSys==MKSYS_ITEMMONIKER){
481 IMoniker_AddRef(iface);
483 *ppmkPrefix=iface;
485 IMoniker_AddRef(iface);
487 return MK_S_US;
489 else
490 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
493 /******************************************************************************
494 * AntiMoniker_RelativePathTo
495 ******************************************************************************/
496 HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
498 TRACE(ole,"(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
500 if (ppmkRelPath==NULL)
501 return E_POINTER;
503 IMoniker_AddRef(pmOther);
505 *ppmkRelPath=pmOther;
507 return MK_S_HIM;
510 /******************************************************************************
511 * AntiMoniker_GetDisplayName
512 ******************************************************************************/
513 HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,
514 IBindCtx* pbc,
515 IMoniker* pmkToLeft,
516 LPOLESTR *ppszDisplayName)
518 WCHAR back[]={'\\','.','.',0};
520 TRACE(ole,"(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
522 if (ppszDisplayName==NULL)
523 return E_POINTER;
525 if (pmkToLeft!=NULL){
526 FIXME(ole,"() pmkToLeft!=NULL not implemented \n");
527 return E_NOTIMPL;
530 *ppszDisplayName=CoTaskMemAlloc(sizeof(back));
532 if (*ppszDisplayName==NULL)
533 return E_OUTOFMEMORY;
535 lstrcpyW(*ppszDisplayName,back);
537 return S_OK;
540 /******************************************************************************
541 * AntiMoniker_ParseDisplayName
542 ******************************************************************************/
543 HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,
544 IBindCtx* pbc,
545 IMoniker* pmkToLeft,
546 LPOLESTR pszDisplayName,
547 ULONG* pchEaten,
548 IMoniker** ppmkOut)
550 TRACE(ole,"(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
551 return E_NOTIMPL;
554 /******************************************************************************
555 * AntiMoniker_IsSystemMonker
556 ******************************************************************************/
557 HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
559 TRACE(ole,"(%p,%p)\n",iface,pwdMksys);
561 if (!pwdMksys)
562 return E_POINTER;
564 (*pwdMksys)=MKSYS_ANTIMONIKER;
566 return S_OK;
569 /*******************************************************************************
570 * AntiMonikerIROTData_QueryInterface
571 *******************************************************************************/
572 HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
575 ICOM_THIS_From_IROTData(IMoniker, iface);
577 TRACE(ole,"(%p,%p,%p)\n",iface,riid,ppvObject);
579 return AntiMonikerImpl_QueryInterface(This, riid, ppvObject);
582 /***********************************************************************
583 * AntiMonikerIROTData_AddRef
585 ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
587 ICOM_THIS_From_IROTData(IMoniker, iface);
589 TRACE(ole,"(%p)\n",iface);
591 return AntiMonikerImpl_AddRef(This);
594 /***********************************************************************
595 * AntiMonikerIROTData_Release
597 ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
599 ICOM_THIS_From_IROTData(IMoniker, iface);
601 TRACE(ole,"(%p)\n",iface);
603 return AntiMonikerImpl_Release(This);
606 /******************************************************************************
607 * AntiMonikerIROTData_GetComparaisonData
608 ******************************************************************************/
609 HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
610 BYTE* pbData,
611 ULONG cbMax,
612 ULONG* pcbData)
614 FIXME(ole,"(),stub!\n");
615 return E_NOTIMPL;
618 /******************************************************************************
619 * CreateAntiMoniker [OLE.55]
620 ******************************************************************************/
621 HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
623 AntiMonikerImpl* newAntiMoniker = 0;
624 HRESULT hr = S_OK;
625 IID riid=IID_IMoniker;
627 TRACE(ole,"(%p)\n",ppmk);
629 newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));
631 if (newAntiMoniker == 0)
632 return STG_E_INSUFFICIENTMEMORY;
634 hr = AntiMonikerImpl_Construct(newAntiMoniker);
636 if (FAILED(hr)){
638 HeapFree(GetProcessHeap(),0,newAntiMoniker);
639 return hr;
642 hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk);
644 return hr;