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