- New implementation of SendMessage, ReceiveMessage, ReplyMessage functions
[wine] / ole / itemmoniker.c
1 /***************************************************************************************
2  *                            ItemMonikers implementation
3  *
4  *           Copyright 1999  Noomen Hamza
5  ***************************************************************************************/
6
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <assert.h>
11 #include "winerror.h"
12 #include "wine/obj_base.h"
13 #include "wine/obj_storage.h"
14 #include "wine/obj_moniker.h"
15 #include "debug.h"
16 #include "heap.h"
17
18 typedef struct ItemMonikerImpl{
19
20     ICOM_VTABLE(IMoniker)*  lpvtbl;
21
22     ULONG ref;
23
24 } ItemMonikerImpl;
25
26 static HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
27 static ULONG   WINAPI ItemMonikerImpl_AddRef(IMoniker* iface);
28 static ULONG   WINAPI ItemMonikerImpl_Release(IMoniker* iface);
29 static HRESULT WINAPI ItemMonikerImpl_GetClassID(const IMoniker* iface, CLSID *pClassID);
30 static HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface);
31 static HRESULT WINAPI ItemMonikerImpl_Load(IMoniker* iface, IStream32* pStm);
32 static HRESULT WINAPI ItemMonikerImpl_Save(IMoniker* iface, IStream32* pStm, BOOL32 fClearDirty);
33 static HRESULT WINAPI ItemMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
34 static HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
35 static HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
36 static HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
37 static HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL32 fOnlyIfNotGeneric, IMoniker** ppmkComposite);
38 static HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL32 fForward, IEnumMoniker** ppenumMoniker);
39 static HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
40 static HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
41 static HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
42 static HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pItemTime);
43 static HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
44 static HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
45 static HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
46 static HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR32 *ppszDisplayName);
47 static HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR32 pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
48 static HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
49
50 static HRESULT WINAPI ItemMonikerImpl_Construct(ItemMonikerImpl* iface, LPCOLESTR32 lpszDelim,LPCOLESTR32 lpszItem);
51 static HRESULT WINAPI ItemMonikerImpl_Destroy(ItemMonikerImpl* iface);
52
53 // Virtual function table for the ItemMonikerImpl class.
54 static ICOM_VTABLE(IMoniker) VT_ItemMonikerImpl =
55     {
56     ItemMonikerImpl_QueryInterface,
57     ItemMonikerImpl_AddRef,
58     ItemMonikerImpl_Release,
59     ItemMonikerImpl_GetClassID,
60     ItemMonikerImpl_IsDirty,
61     ItemMonikerImpl_Load,
62     ItemMonikerImpl_Save,
63     ItemMonikerImpl_GetSizeMax,
64     ItemMonikerImpl_BindToObject,
65     ItemMonikerImpl_BindToStorage,
66     ItemMonikerImpl_Reduce,
67     ItemMonikerImpl_ComposeWith,
68     ItemMonikerImpl_Enum,
69     ItemMonikerImpl_IsEqual,
70     ItemMonikerImpl_Hash,
71     ItemMonikerImpl_IsRunning,
72     ItemMonikerImpl_GetTimeOfLastChange,
73     ItemMonikerImpl_Inverse,
74     ItemMonikerImpl_CommonPrefixWith,
75     ItemMonikerImpl_RelativePathTo,
76     ItemMonikerImpl_GetDisplayName,
77     ItemMonikerImpl_ParseDisplayName,
78     ItemMonikerImpl_IsSystemMoniker
79 };
80
81 /*******************************************************************************
82  *        ItemMoniker_QueryInterface
83  *******************************************************************************/
84 HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
85 {
86     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
87
88   TRACE(ole,"(%p,%p,%p)\n",This,riid,ppvObject);
89
90   // Perform a sanity check on the parameters.
91   if ( (This==0) || (ppvObject==0) )    return E_INVALIDARG;
92   
93   // Initialize the return parameter.
94   *ppvObject = 0;
95
96   // Compare the riid with the interface IDs implemented by this object.
97   if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
98       *ppvObject = (IMoniker*)This;
99   else
100       if (memcmp(&IID_IPersist, riid, sizeof(IID_IPersist)) == 0)
101           *ppvObject = (IMoniker*)This;
102       else
103           if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
104               *ppvObject = (IMoniker*)This;
105           else
106               if (memcmp(&IID_IMoniker, riid, sizeof(IID_IMoniker)) == 0)
107                   *ppvObject = (IMoniker*)This;
108
109   // Check that we obtained an interface.
110   if ((*ppvObject)==0)        return E_NOINTERFACE;
111   
112    // Query Interface always increases the reference count by one when it is successful
113   ItemMonikerImpl_AddRef(iface);
114
115   return S_OK;
116 }
117
118 /******************************************************************************
119  *        ItemMoniker_AddRef
120  ******************************************************************************/
121 ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface)
122 {
123     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
124
125     TRACE(ole,"(%p)\n",This);
126
127     return ++(This->ref);
128 }
129
130 /******************************************************************************
131  *        ItemMoniker_Release
132  ******************************************************************************/
133 ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface)
134 {
135     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
136
137     TRACE(ole,"(%p),stub!\n",This);
138
139     This->ref--;
140
141     if (This->ref==0){
142         ItemMonikerImpl_Destroy(This);
143         return 0;
144     }
145
146     return This->ref;
147 }
148
149 /******************************************************************************
150  *        ItemMoniker_GetClassID
151  ******************************************************************************/
152 HRESULT WINAPI ItemMonikerImpl_GetClassID(const IMoniker* iface, CLSID *pClassID)//Pointer to CLSID of object
153 {
154     FIXME(ole,"(%p),stub!\n",pClassID);
155     return E_NOTIMPL;
156 }
157
158 /******************************************************************************
159  *        ItemMoniker_IsDirty
160  ******************************************************************************/
161 HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface)
162 {
163     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
164
165     FIXME(ole,"(%p),stub!\n",This);
166     return E_NOTIMPL;
167 }
168
169 /******************************************************************************
170  *        ItemMoniker_Load
171  ******************************************************************************/
172 HRESULT WINAPI ItemMonikerImpl_Load(
173           IMoniker* iface,
174           IStream32* pStm)
175 {
176     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
177
178     FIXME(ole,"(%p,%p),stub!\n",This,pStm);
179     return E_NOTIMPL;
180 }
181
182 /******************************************************************************
183  *        ItemMoniker_Save
184  ******************************************************************************/
185 HRESULT WINAPI ItemMonikerImpl_Save(
186           IMoniker* iface,
187           IStream32* pStm,
188           BOOL32 fClearDirty)
189 {
190     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
191
192     FIXME(ole,"(%p,%p,%d),stub!\n",This,pStm,fClearDirty);
193     return E_NOTIMPL;
194 }
195
196 /******************************************************************************
197  *        ItemMoniker_GetSizeMax
198  ******************************************************************************/
199 HRESULT WINAPI ItemMonikerImpl_GetSizeMax(
200           IMoniker* iface,
201           ULARGE_INTEGER* pcbSize)
202 {
203     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
204
205     FIXME(ole,"(%p,%p),stub!\n",This,pcbSize);
206     return E_NOTIMPL;
207 }
208
209 /******************************************************************************
210  *         ItemMoniker_Construct
211  *******************************************************************************/
212 HRESULT WINAPI ItemMonikerImpl_Construct(ItemMonikerImpl* This, LPCOLESTR32 lpszDelim,LPCOLESTR32 lpszItem){
213
214     FIXME(ole,"(%p,%p,%p),stub!\n",This,lpszDelim,lpszItem);
215
216     memset(This, 0, sizeof(ItemMonikerImpl));
217
218     //Initialize the virtual fgunction table.
219     This->lpvtbl       = &VT_ItemMonikerImpl;
220     return S_OK;
221 }
222
223 /******************************************************************************
224  *        ItemMoniker_Destroy
225  *******************************************************************************/
226 HRESULT WINAPI ItemMonikerImpl_Destroy(ItemMonikerImpl* This){
227
228     FIXME(ole,"(%p),stub!\n",This);
229
230     SEGPTR_FREE(This);
231     return S_OK;
232 }
233
234 /******************************************************************************
235  *                  ItemMoniker_BindToObject
236  ******************************************************************************/
237 HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft,
238                                             REFIID riid, VOID** ppvResult)
239 {
240     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
241     
242     FIXME(ole,"(%p,%p,%p,%p,%p),stub!\n",This,pbc,pmkToLeft,riid,ppvResult);
243     return E_NOTIMPL;
244 }
245
246 /******************************************************************************
247  *        ItemMoniker_BindToStorage
248  ******************************************************************************/
249 HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft,
250                                              REFIID riid, VOID** ppvResult)
251 {
252     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
253
254     FIXME(ole,"(%p,%p,%p,%p,%p),stub!\n",This,pbc,pmkToLeft,riid,ppvResult);
255     return E_NOTIMPL;
256 }
257
258 /******************************************************************************
259  *        ItemMoniker_Reduce
260  ******************************************************************************/
261 HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,
262                                       IMoniker** ppmkToLeft, IMoniker** ppmkReduced)
263 {
264     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
265
266     FIXME(ole,"(%p,%p,%ld,%p,%p),stub!\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
267     return E_NOTIMPL;
268 }
269
270 /******************************************************************************
271  *        ItemMoniker_ComposeWith
272  ******************************************************************************/
273 HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL32 fOnlyIfNotGeneric,
274                                            IMoniker** ppmkComposite)
275 {
276     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
277
278     FIXME(ole,"(%p,%p,%d,%p),stub!\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
279     return E_NOTIMPL;
280 }
281
282 /******************************************************************************
283  *        ItemMoniker_Enum
284  ******************************************************************************/
285 HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL32 fForward, IEnumMoniker** ppenumMoniker)
286 {
287     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
288
289     FIXME(ole,"(%p,%d,%p),stub!\n",This,fForward,ppenumMoniker);
290     return E_NOTIMPL;
291
292 }
293
294 /******************************************************************************
295  *        ItemMoniker_IsEqual
296  ******************************************************************************/
297 HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
298 {
299     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
300
301     FIXME(ole,"(%p,%p),stub!\n",This,pmkOtherMoniker);
302     return E_NOTIMPL;
303 }
304
305 /******************************************************************************
306  *        ItemMoniker_Hash
307  ******************************************************************************/
308 HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
309 {
310     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
311
312     FIXME(ole,"(%p,%p),stub!\n",This,pdwHash);
313     return E_NOTIMPL;
314 }
315
316 /******************************************************************************
317  *        ItemMoniker_IsRunning
318  ******************************************************************************/
319 HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft,
320                                          IMoniker* pmkNewlyRunning)
321 {
322     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
323
324     FIXME(ole,"(%p,%p,%p,%p),stub!\n",This,pbc,pmkToLeft,pmkNewlyRunning);
325     return E_NOTIMPL;
326 }
327
328 /******************************************************************************
329  *        ItemMoniker_GetTimeOfLastChange
330  ******************************************************************************/
331 HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
332                                                    FILETIME* pFileTime)
333 {
334     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
335
336     FIXME(ole,"(%p,%p,%p,%p),stub!\n",This,pbc,pmkToLeft,pFileTime);
337     return E_NOTIMPL;
338 }
339
340 /******************************************************************************
341  *        ItemMoniker_Inverse
342  ******************************************************************************/
343 HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
344 {
345     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
346
347     FIXME(ole,"(%p,%p),stub!\n",This,ppmk);
348     return E_NOTIMPL;
349 }
350
351 /******************************************************************************
352  *        ItemMoniker_CommonPrefixWith
353  ******************************************************************************/
354 HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,
355                                                 IMoniker** ppmkPrefix)
356 {
357     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
358
359     FIXME(ole,"(%p,%p,%p),stub!\n",This,pmkOther,ppmkPrefix);
360     return E_NOTIMPL;
361 }
362
363 /******************************************************************************
364  *        ItemMoniker_RelativePathTo
365  ******************************************************************************/
366 HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
367 {
368     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
369
370     FIXME(ole,"(%p,%p,%p),stub!\n",This,pmOther,ppmkRelPath);
371     return E_NOTIMPL;
372 }
373
374 /******************************************************************************
375  *        ItemMoniker_GetDisplayName
376  ******************************************************************************/
377 HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft,
378                                               LPOLESTR32 *ppszDisplayName)
379 {
380     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
381
382     FIXME(ole,"(%p,%p,%p,%p),stub!\n",This,pbc,pmkToLeft,ppszDisplayName);
383     return E_NOTIMPL;
384 }
385
386 /******************************************************************************
387  *        ItemMoniker_ParseDisplayName
388  ******************************************************************************/
389 HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft,
390                                                 LPOLESTR32 pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut)
391 {
392     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
393
394     FIXME(ole,"(%p,%p,%p,%p,%p,%p),stub!\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
395     return E_NOTIMPL;
396 }
397
398 /******************************************************************************
399  *        ItemMoniker_IsSystemMonker
400  ******************************************************************************/
401 HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
402 {
403     ItemMonikerImpl* This=(ItemMonikerImpl*)iface;
404
405     FIXME(ole,"(%p,%p),stub!\n",This,pwdMksys);
406     return E_NOTIMPL;
407 }
408
409 /******************************************************************************
410  *        CreateItemMoniker16   [OLE2.28]
411  ******************************************************************************/
412 HRESULT WINAPI CreateItemMoniker16(LPCOLESTR16 lpszDelim,LPCOLESTR32  lpszItem,LPMONIKER* ppmk){// [in] pathname [out] new moniker object
413
414     FIXME(ole,"(%s,%p),stub!\n",lpszDelim,ppmk);
415     *ppmk = NULL;
416     return E_NOTIMPL;
417 }
418
419 /******************************************************************************
420  *        CreateItemMoniker32   [OLE32.55]
421  ******************************************************************************/
422 HRESULT WINAPI CreateItemMoniker32(LPCOLESTR32 lpszDelim,LPCOLESTR32  lpszItem, LPMONIKER * ppmk)
423 {
424
425     ItemMonikerImpl* newItemMoniker = 0;
426     HRESULT        hr = S_OK;
427
428     TRACE(ole,"(%p,%p,%p)\n",lpszDelim,lpszItem,ppmk);
429
430     newItemMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl));
431
432     if (newItemMoniker == 0)
433         return STG_E_INSUFFICIENTMEMORY;
434
435     hr = ItemMonikerImpl_Construct(newItemMoniker,lpszDelim,lpszItem);
436
437     if (FAILED(hr))
438         return hr;
439
440     hr = ItemMonikerImpl_QueryInterface((IMoniker*)newItemMoniker,&IID_IMoniker,(void**)ppmk);
441
442     return hr;
443 }