Implement ClearCustData.
[wine] / dlls / ole32 / filemoniker.c
1 /***************************************************************************************
2  *                            FileMonikers implementation
3  *
4  *               Copyright 1999  Noomen Hamza
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  ***************************************************************************************/
20
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <string.h>
24
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "winnls.h"
31 #include "wine/unicode.h"
32 #include "wine/debug.h"
33 #include "objbase.h"
34 #include "moniker.h"
35
36 #include "compobj_private.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(ole);
39
40 const CLSID CLSID_FileMoniker = {
41   0x303, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
42 };
43
44 /* filemoniker data structure */
45 typedef struct FileMonikerImpl{
46
47     ICOM_VTABLE(IMoniker)*  lpvtbl1;  /* VTable relative to the IMoniker interface.*/
48
49     /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
50      * two monikers are equal. That's whay IROTData interface is implemented by monikers.
51      */
52     ICOM_VTABLE(IROTData)*  lpvtbl2;  /* VTable relative to the IROTData interface.*/
53
54     ULONG ref; /* reference counter for this object */
55
56     LPOLESTR filePathName; /* path string identified by this filemoniker */
57
58 } FileMonikerImpl;
59
60 /********************************************************************************/
61 /* FileMoniker prototype functions :                                            */
62
63 /* IUnknown prototype functions */
64 static HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
65 static ULONG   WINAPI FileMonikerImpl_AddRef(IMoniker* iface);
66 static ULONG   WINAPI FileMonikerImpl_Release(IMoniker* iface);
67
68 /* IPersist prototype functions */
69 static HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
70
71 /* IPersistStream prototype functions */
72 static HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface);
73 static HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface, IStream* pStm);
74 static HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
75 static HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
76
77 /* IMoniker prototype functions */
78 static HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
79 static HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
80 static HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
81 static HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
82 static HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
83 static HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
84 static HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
85 static HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
86 static HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime);
87 static HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
88 static HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
89 static HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
90 static HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
91 static HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
92 static HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
93
94 /********************************************************************************/
95 /* IROTData prototype functions                                                 */
96
97 /* IUnknown prototype functions */
98 static HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
99 static ULONG   WINAPI FileMonikerROTDataImpl_AddRef(IROTData* iface);
100 static ULONG   WINAPI FileMonikerROTDataImpl_Release(IROTData* iface);
101
102 /* IROTData prototype function */
103 static HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
104
105 /* Local function used by filemoniker implementation */
106 HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* iface, LPCOLESTR lpszPathName);
107 HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* iface);
108 int     WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** tabStr);
109
110
111 /********************************************************************************/
112 /* Virtual function table for the FileMonikerImpl class which  include IPersist,*/
113 /* IPersistStream and IMoniker functions.                                       */
114 static ICOM_VTABLE(IMoniker) VT_FileMonikerImpl =
115 {
116     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
117     FileMonikerImpl_QueryInterface,
118     FileMonikerImpl_AddRef,
119     FileMonikerImpl_Release,
120     FileMonikerImpl_GetClassID,
121     FileMonikerImpl_IsDirty,
122     FileMonikerImpl_Load,
123     FileMonikerImpl_Save,
124     FileMonikerImpl_GetSizeMax,
125     FileMonikerImpl_BindToObject,
126     FileMonikerImpl_BindToStorage,
127     FileMonikerImpl_Reduce,
128     FileMonikerImpl_ComposeWith,
129     FileMonikerImpl_Enum,
130     FileMonikerImpl_IsEqual,
131     FileMonikerImpl_Hash,
132     FileMonikerImpl_IsRunning,
133     FileMonikerImpl_GetTimeOfLastChange,
134     FileMonikerImpl_Inverse,
135     FileMonikerImpl_CommonPrefixWith,
136     FileMonikerImpl_RelativePathTo,
137     FileMonikerImpl_GetDisplayName,
138     FileMonikerImpl_ParseDisplayName,
139     FileMonikerImpl_IsSystemMoniker
140 };
141
142 /********************************************************************************/
143 /* Virtual function table for the IROTData class.                               */
144 static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
145 {
146     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
147     FileMonikerROTDataImpl_QueryInterface,
148     FileMonikerROTDataImpl_AddRef,
149     FileMonikerROTDataImpl_Release,
150     FileMonikerROTDataImpl_GetComparaisonData
151 };
152
153 /*******************************************************************************
154  *        FileMoniker_QueryInterface
155  *******************************************************************************/
156 HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
157 {
158     ICOM_THIS(FileMonikerImpl,iface);
159
160   TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
161
162     /* Perform a sanity check on the parameters.*/
163     if ( (This==0) || (ppvObject==0) )
164         return E_INVALIDARG;
165
166     /* Initialize the return parameter */
167   *ppvObject = 0;
168
169     /* Compare the riid with the interface IDs implemented by this object.*/
170     if (IsEqualIID(&IID_IUnknown, riid)      ||
171         IsEqualIID(&IID_IPersist, riid)      ||
172         IsEqualIID(&IID_IPersistStream,riid) ||
173         IsEqualIID(&IID_IMoniker, riid)
174        )
175         *ppvObject = iface;
176
177     else if (IsEqualIID(&IID_IROTData, riid))
178         *ppvObject = (IROTData*)&(This->lpvtbl2);
179
180     /* Check that we obtained an interface.*/
181     if ((*ppvObject)==0)
182         return E_NOINTERFACE;
183
184     /* Query Interface always increases the reference count by one when it is successful */
185   FileMonikerImpl_AddRef(iface);
186
187     return S_OK;
188 }
189
190 /******************************************************************************
191  *        FileMoniker_AddRef
192  ******************************************************************************/
193 ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface)
194 {
195     ICOM_THIS(FileMonikerImpl,iface);
196
197     TRACE("(%p)\n",iface);
198
199     return ++(This->ref);
200 }
201
202 /******************************************************************************
203  *        FileMoniker_Release
204  ******************************************************************************/
205 ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface)
206 {
207     ICOM_THIS(FileMonikerImpl,iface);
208
209     TRACE("(%p)\n",iface);
210
211     This->ref--;
212
213     /* destroy the object if there's no more reference on it */
214     if (This->ref==0){
215
216         FileMonikerImpl_Destroy(This);
217
218         return 0;
219     }
220     return This->ref;
221 }
222
223 /******************************************************************************
224  *        FileMoniker_GetClassID
225  ******************************************************************************/
226 HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface,
227                                           CLSID *pClassID)/* Pointer to CLSID of object */
228 {
229     TRACE("(%p,%p),stub!\n",iface,pClassID);
230
231     if (pClassID==NULL)
232         return E_POINTER;
233
234     *pClassID = CLSID_FileMoniker;
235
236     return S_OK;
237 }
238
239 /******************************************************************************
240  *        FileMoniker_IsDirty
241  ******************************************************************************/
242 HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface)
243 {
244     /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
245        method in the OLE-provided moniker interfaces always return S_FALSE because
246        their internal state never changes. */
247
248     TRACE("(%p)\n",iface);
249
250     return S_FALSE;
251 }
252
253 /******************************************************************************
254  *        FileMoniker_Load
255  ******************************************************************************/
256 HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface,IStream* pStm)
257 {
258     HRESULT res;
259     CHAR* filePathA;
260     WCHAR* filePathW;
261     ULONG bread;
262     WORD  wbuffer;
263     DWORD dwbuffer,length,i,doubleLenHex,doubleLenDec;
264
265     ICOM_THIS(FileMonikerImpl,iface);
266
267     TRACE("(%p,%p)\n",iface,pStm);
268
269     /* this function locates and reads from the stream the filePath string written by FileMonikerImpl_Save */
270
271     /* first WORD is non significative */
272     res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
273     if (bread!=sizeof(WORD) || wbuffer!=0)
274         return E_FAIL;
275
276     /* read filePath string length (plus one) */
277     res=IStream_Read(pStm,&length,sizeof(DWORD),&bread);
278     if (bread != sizeof(DWORD))
279         return E_FAIL;
280
281     /* read filePath string */
282     filePathA=HeapAlloc(GetProcessHeap(),0,length);
283     res=IStream_Read(pStm,filePathA,length,&bread);
284     HeapFree(GetProcessHeap(),0,filePathA);
285     if (bread != length)
286         return E_FAIL;
287
288     /* read the first constant */
289     IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
290     if (bread != sizeof(DWORD) || dwbuffer != 0xDEADFFFF)
291         return E_FAIL;
292
293     length--;
294
295     for(i=0;i<10;i++){
296         res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
297         if (bread!=sizeof(WORD) || wbuffer!=0)
298             return E_FAIL;
299     }
300
301     if (length>8)
302         length=0;
303
304     doubleLenHex=doubleLenDec=2*length;
305     if (length > 5)
306         doubleLenDec+=6;
307
308     res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
309     if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenDec)
310         return E_FAIL;
311
312     if (length==0)
313         return res;
314
315     res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
316     if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenHex)
317         return E_FAIL;
318
319     res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
320     if (bread!=sizeof(WORD) || wbuffer!=0x3)
321         return E_FAIL;
322
323     filePathW=HeapAlloc(GetProcessHeap(),0,(length+1)*sizeof(WCHAR));
324     filePathW[length]=0;
325     res=IStream_Read(pStm,filePathW,doubleLenHex,&bread);
326     if (bread!=doubleLenHex) {
327         HeapFree(GetProcessHeap(), 0, filePathW);
328         return E_FAIL;
329     }
330
331     if (This->filePathName!=NULL)
332         HeapFree(GetProcessHeap(),0,This->filePathName);
333
334     This->filePathName=filePathW;
335
336     return res;
337 }
338
339 /******************************************************************************
340  *        FileMoniker_Save
341  ******************************************************************************/
342 HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface,
343                                     IStream* pStm,/* pointer to the stream where the object is to be saved */
344                                     BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
345 {
346     /* this function saves data of this object. In the beginning I thougth
347      * that I have just to write the filePath string on Stream. But, when I
348      * tested this function whith windows programs samples, I noticed that it
349      * was not the case. So I analysed data written by this function on
350      * Windows and what this did function exactly ! But I have no idea about
351      * its logic !
352      * I guessed data which must be written on stream is:
353      * 1) WORD constant:zero
354      * 2) length of the path string ("\0" included)
355      * 3) path string type A
356      * 4) DWORD constant : 0xDEADFFFF
357      * 5) ten WORD constant: zero
358      * 6) DWORD: double-length of the the path string type W ("\0" not
359      *    included)
360      * 7) WORD constant: 0x3
361      * 8) filePath unicode string.
362      *    if the length(filePath) > 8 or length(filePath) == 8 stop at step 5)
363      */
364
365     ICOM_THIS(FileMonikerImpl,iface);
366
367     HRESULT res;
368     LPOLESTR filePathW=This->filePathName;
369     CHAR*     filePathA;
370     DWORD  len;
371
372     DWORD  constant1 = 0xDEADFFFF; /* these constants are detected after analysing the data structure written by */
373     WORD   constant2 = 0x3;        /* FileMoniker_Save function in a windows program system */
374
375     WORD   zero=0;
376     DWORD doubleLenHex;
377     DWORD doubleLenDec;
378     int i=0;
379
380     TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty);
381
382     if (pStm==NULL)
383         return E_POINTER;
384
385     /* write a DWORD set to 0 : constant */
386     res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
387
388     /* write length of filePath string ( "\0" included )*/
389     len = WideCharToMultiByte( CP_ACP, 0, filePathW, -1, NULL, 0, NULL, NULL );
390     res=IStream_Write(pStm,&len,sizeof(DWORD),NULL);
391
392     /* write filePath string type A */
393     filePathA=HeapAlloc(GetProcessHeap(),0,len);
394     WideCharToMultiByte( CP_ACP, 0, filePathW, -1, filePathA, len, NULL, NULL );
395     res=IStream_Write(pStm,filePathA,len,NULL);
396     HeapFree(GetProcessHeap(),0,filePathA);
397
398     /* write a DWORD set to 0xDEADFFFF: constant */
399     res=IStream_Write(pStm,&constant1,sizeof(DWORD),NULL);
400
401     len--;
402     /* write 10 times a DWORD set to 0 : constants */
403     for(i=0;i<10;i++)
404         res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
405
406     if (len>8)
407         len=0;
408
409     doubleLenHex=doubleLenDec=2*len;
410     if (len > 5)
411         doubleLenDec+=6;
412
413     /* write double-length of the path string ( "\0" included )*/
414     res=IStream_Write(pStm,&doubleLenDec,sizeof(DWORD),NULL);
415
416     if (len==0)
417         return res;
418
419     /* write double-length (hexa representation) of the path string ( "\0" included ) */
420     res=IStream_Write(pStm,&doubleLenHex,sizeof(DWORD),NULL);
421
422     /* write a WORD set to 0x3: constant */
423     res=IStream_Write(pStm,&constant2,sizeof(WORD),NULL);
424
425     /* write path unicode string */
426     res=IStream_Write(pStm,filePathW,doubleLenHex,NULL);
427
428     return res;
429 }
430
431 /******************************************************************************
432  *        FileMoniker_GetSizeMax
433  ******************************************************************************/
434 HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface,
435                                           ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
436 {
437     ICOM_THIS(FileMonikerImpl,iface);
438     DWORD len=lstrlenW(This->filePathName);
439     DWORD sizeMAx;
440
441     TRACE("(%p,%p)\n",iface,pcbSize);
442
443     if (pcbSize!=NULL)
444         return E_POINTER;
445
446     /* for more details see FileMonikerImpl_Save coments */
447
448     sizeMAx =  sizeof(WORD) +           /* first WORD is 0 */
449                sizeof(DWORD)+           /* length of filePath including "\0" in the end of the string */
450                (len+1)+                 /* filePath string */
451                sizeof(DWORD)+           /* constant : 0xDEADFFFF */
452                10*sizeof(WORD)+         /* 10 zero WORD */
453                sizeof(DWORD);           /* size of the unicode filePath: "\0" not included */
454
455     if (len==0 || len > 8)
456         return S_OK;
457
458     sizeMAx += sizeof(DWORD)+           /* size of the unicode filePath: "\0" not included */
459                sizeof(WORD)+            /* constant : 0x3 */
460                len*sizeof(WCHAR);       /* unicde filePath string */
461
462     pcbSize->u.LowPart=sizeMAx;
463     pcbSize->u.HighPart=0;
464
465     return S_OK;
466 }
467
468 /******************************************************************************
469  *         FileMoniker_Construct (local function)
470  *******************************************************************************/
471 HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* This, LPCOLESTR lpszPathName)
472 {
473     int nb=0,i;
474     int sizeStr=lstrlenW(lpszPathName);
475     LPOLESTR *tabStr=0;
476     static const WCHAR twoPoint[]={'.','.',0};
477     static const WCHAR bkSlash[]={'\\',0};
478     BYTE addBkSlash;
479
480     TRACE("(%p,%p)\n",This,lpszPathName);
481
482     /* Initialize the virtual fgunction table. */
483     This->lpvtbl1      = &VT_FileMonikerImpl;
484     This->lpvtbl2      = &VT_ROTDataImpl;
485     This->ref          = 0;
486
487     This->filePathName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1));
488
489     if (This->filePathName==NULL)
490         return E_OUTOFMEMORY;
491
492     strcpyW(This->filePathName,lpszPathName);
493
494     nb=FileMonikerImpl_DecomposePath(This->filePathName,&tabStr);
495
496     if (nb > 0 ){
497
498         addBkSlash=1;
499         if (lstrcmpW(tabStr[0],twoPoint)!=0)
500             addBkSlash=0;
501         else
502             for(i=0;i<nb;i++){
503
504                 if ( (lstrcmpW(tabStr[i],twoPoint)!=0) && (lstrcmpW(tabStr[i],bkSlash)!=0) ){
505                     addBkSlash=0;
506                     break;
507                 }
508                 else
509
510                     if (lstrcmpW(tabStr[i],bkSlash)==0 && i<nb-1 && lstrcmpW(tabStr[i+1],bkSlash)==0){
511                         *tabStr[i]=0;
512                         sizeStr--;
513                         addBkSlash=0;
514                         break;
515                     }
516             }
517
518         if (lstrcmpW(tabStr[nb-1],bkSlash)==0)
519             addBkSlash=0;
520
521         This->filePathName=HeapReAlloc(GetProcessHeap(),0,This->filePathName,(sizeStr+1)*sizeof(WCHAR));
522
523         *This->filePathName=0;
524
525         for(i=0;tabStr[i]!=NULL;i++)
526             strcatW(This->filePathName,tabStr[i]);
527
528         if (addBkSlash)
529             strcatW(This->filePathName,bkSlash);
530     }
531
532     for(i=0; tabStr[i]!=NULL;i++)
533         CoTaskMemFree(tabStr[i]);
534     CoTaskMemFree(tabStr);
535
536     return S_OK;
537 }
538
539 /******************************************************************************
540  *        FileMoniker_Destroy (local function)
541  *******************************************************************************/
542 HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* This)
543 {
544     TRACE("(%p)\n",This);
545
546     if (This->filePathName!=NULL)
547             HeapFree(GetProcessHeap(),0,This->filePathName);
548
549     HeapFree(GetProcessHeap(),0,This);
550
551     return S_OK;
552 }
553
554 /******************************************************************************
555  *                  FileMoniker_BindToObject
556  ******************************************************************************/
557 HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,
558                                             IBindCtx* pbc,
559                                             IMoniker* pmkToLeft,
560                                             REFIID riid,
561                                             VOID** ppvResult)
562 {
563     HRESULT   res=E_FAIL;
564     CLSID     clsID;
565     IUnknown* pObj=0;
566     IRunningObjectTable *prot=0;
567     IPersistFile  *ppf=0;
568     IClassFactory *pcf=0;
569     IClassActivator *pca=0;
570
571     ICOM_THIS(FileMonikerImpl,iface);
572
573     *ppvResult=0;
574
575     TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
576
577     if(pmkToLeft==NULL){
578
579         res=IBindCtx_GetRunningObjectTable(pbc,&prot);
580
581         if (SUCCEEDED(res)){
582             /* if the requested class was loaded before ! we don't need to reload it */
583             res = IRunningObjectTable_GetObject(prot,iface,&pObj);
584
585             if (res==S_FALSE){
586                 /* first activation of this class */
587                 res=GetClassFile(This->filePathName,&clsID);
588                 if (SUCCEEDED(res)){
589
590                     res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IPersistFile,(void**)&ppf);
591                     if (SUCCEEDED(res)){
592
593                         res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
594                         if (SUCCEEDED(res)){
595
596                             pObj=(IUnknown*)ppf;
597                             IUnknown_AddRef(pObj);
598                         }
599                     }
600                 }
601             }
602         }
603     }
604     else{
605         res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassFactory,(void**)&pcf);
606
607         if (res==E_NOINTERFACE){
608
609             res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassActivator,(void**)&pca);
610
611             if (res==E_NOINTERFACE)
612                 return MK_E_INTERMEDIATEINTERFACENOTSUPPORTED;
613         }
614         if (pcf!=NULL){
615
616             IClassFactory_CreateInstance(pcf,NULL,&IID_IPersistFile,(void**)ppf);
617
618             res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
619
620             if (SUCCEEDED(res)){
621
622                 pObj=(IUnknown*)ppf;
623                 IUnknown_AddRef(pObj);
624             }
625         }
626         if (pca!=NULL){
627
628             FIXME("()\n");
629
630             /*res=GetClassFile(This->filePathName,&clsID);
631
632             if (SUCCEEDED(res)){
633
634                 res=IClassActivator_GetClassObject(pca,&clsID,CLSCTX_ALL,0,&IID_IPersistFile,(void**)&ppf);
635
636                 if (SUCCEEDED(res)){
637
638                     pObj=(IUnknown*)ppf;
639                     IUnknown_AddRef(pObj);
640                 }
641             }*/
642         }
643     }
644
645     if (pObj!=NULL){
646         /* get the requested interface from the loaded class */
647         res= IUnknown_QueryInterface(pObj,riid,ppvResult);
648
649         IBindCtx_RegisterObjectBound(pbc,(IUnknown*)*ppvResult);
650
651         IUnknown_Release(pObj);
652     }
653
654     if (prot!=NULL)
655         IRunningObjectTable_Release(prot);
656
657     if (ppf!=NULL)
658         IPersistFile_Release(ppf);
659
660     if (pca!=NULL)
661         IClassActivator_Release(pca);
662
663     if (pcf!=NULL)
664         IClassFactory_Release(pcf);
665
666     return res;
667 }
668
669 /******************************************************************************
670  *        FileMoniker_BindToStorage
671  ******************************************************************************/
672 HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,
673                                              IBindCtx* pbc,
674                                              IMoniker* pmkToLeft,
675                                              REFIID riid,
676                                              VOID** ppvObject)
677 {
678     LPOLESTR filePath=0;
679     IStorage *pstg=0;
680     HRESULT res;
681
682     TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
683
684     if (pmkToLeft==NULL){
685
686         if (IsEqualIID(&IID_IStorage, riid)){
687
688             /* get the file name */
689             FileMonikerImpl_GetDisplayName(iface,pbc,pmkToLeft,&filePath);
690
691             /* verifie if the file contains a storage object */
692             res=StgIsStorageFile(filePath);
693
694             if(res==S_OK){
695
696                 res=StgOpenStorage(filePath,NULL,STGM_READWRITE|STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
697
698                 if (SUCCEEDED(res)){
699
700                     *ppvObject=pstg;
701
702                     IStorage_AddRef(pstg);
703
704                     return res;
705                 }
706             }
707             CoTaskMemFree(filePath);
708         }
709         else
710             if ( (IsEqualIID(&IID_IStream, riid)) || (IsEqualIID(&IID_ILockBytes, riid)) )
711                 return E_FAIL;
712             else
713                 return E_NOINTERFACE;
714     }
715     else {
716
717         FIXME("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
718
719         return E_NOTIMPL;
720     }
721     return res;
722 }
723
724 /******************************************************************************
725  *        FileMoniker_Reduce
726  ******************************************************************************/
727 HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,
728                                       IBindCtx* pbc,
729                                       DWORD dwReduceHowFar,
730                                       IMoniker** ppmkToLeft,
731                                       IMoniker** ppmkReduced)
732 {
733     TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
734
735     if (ppmkReduced==NULL)
736         return E_POINTER;
737
738     FileMonikerImpl_AddRef(iface);
739
740     *ppmkReduced=iface;
741
742     return MK_S_REDUCED_TO_SELF;
743 }
744 /******************************************************************************
745  *        FileMoniker_ComposeWith
746  ******************************************************************************/
747 HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,
748                                            IMoniker* pmkRight,
749                                            BOOL fOnlyIfNotGeneric,
750                                            IMoniker** ppmkComposite)
751 {
752     HRESULT res;
753     LPOLESTR str1=0,str2=0,*strDec1=0,*strDec2=0,newStr=0;
754     static const WCHAR twoPoint[]={'.','.',0};
755     static const WCHAR bkSlash[]={'\\',0};
756     IBindCtx *bind=0;
757     int i=0,j=0,lastIdx1=0,lastIdx2=0;
758     DWORD mkSys;
759
760     TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
761
762     if (ppmkComposite==NULL)
763         return E_POINTER;
764
765     if (pmkRight==NULL)
766         return E_INVALIDARG;
767
768     *ppmkComposite=0;
769
770     IMoniker_IsSystemMoniker(pmkRight,&mkSys);
771
772     /* check if we have two filemonikers to compose or not */
773     if(mkSys==MKSYS_FILEMONIKER){
774
775         CreateBindCtx(0,&bind);
776
777         FileMonikerImpl_GetDisplayName(iface,bind,NULL,&str1);
778         IMoniker_GetDisplayName(pmkRight,bind,NULL,&str2);
779
780         /* decompose pathnames of the two monikers : (to prepare the path merge operation ) */
781         lastIdx1=FileMonikerImpl_DecomposePath(str1,&strDec1)-1;
782         lastIdx2=FileMonikerImpl_DecomposePath(str2,&strDec2)-1;
783
784         if ((lastIdx1==-1 && lastIdx2>-1)||(lastIdx1==1 && lstrcmpW(strDec1[0],twoPoint)==0))
785             return MK_E_SYNTAX;
786
787         if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0)
788             lastIdx1--;
789
790         /* for etch "..\" in the left of str2 remove the right element from str1 */
791         for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ) ;i+=2){
792
793             lastIdx1-=2;
794         }
795
796         /* the length of the composed path string  is raised by the sum of the two paths lengths  */
797         newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
798
799           if (newStr==NULL)
800                 return E_OUTOFMEMORY;
801
802         /* new path is the concatenation of the rest of str1 and str2 */
803         for(*newStr=0,j=0;j<=lastIdx1;j++)
804             strcatW(newStr,strDec1[j]);
805
806         if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
807             strcatW(newStr,bkSlash);
808
809         for(j=i;j<=lastIdx2;j++)
810             strcatW(newStr,strDec2[j]);
811
812         /* create a new moniker with the new string */
813         res=CreateFileMoniker(newStr,ppmkComposite);
814
815         /* free all strings space memory used by this function */
816         HeapFree(GetProcessHeap(),0,newStr);
817
818         for(i=0; strDec1[i]!=NULL;i++)
819             CoTaskMemFree(strDec1[i]);
820         for(i=0; strDec2[i]!=NULL;i++)
821             CoTaskMemFree(strDec2[i]);
822         CoTaskMemFree(strDec1);
823         CoTaskMemFree(strDec2);
824
825         CoTaskMemFree(str1);
826         CoTaskMemFree(str2);
827
828         return res;
829     }
830     else if(mkSys==MKSYS_ANTIMONIKER){
831
832         *ppmkComposite=NULL;
833         return S_OK;
834     }
835     else if (fOnlyIfNotGeneric){
836
837         *ppmkComposite=NULL;
838         return MK_E_NEEDGENERIC;
839     }
840     else
841
842         return CreateGenericComposite(iface,pmkRight,ppmkComposite);
843 }
844
845 /******************************************************************************
846  *        FileMoniker_Enum
847  ******************************************************************************/
848 HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
849 {
850     TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
851
852     if (ppenumMoniker == NULL)
853         return E_POINTER;
854
855     *ppenumMoniker = NULL;
856
857     return S_OK;
858 }
859
860 /******************************************************************************
861  *        FileMoniker_IsEqual
862  ******************************************************************************/
863 HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
864 {
865     ICOM_THIS(FileMonikerImpl,iface);
866     CLSID clsid;
867     LPOLESTR filePath;
868     IBindCtx* bind;
869     HRESULT res;
870
871     TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
872
873     if (pmkOtherMoniker==NULL)
874         return S_FALSE;
875
876     IMoniker_GetClassID(pmkOtherMoniker,&clsid);
877
878     if (!IsEqualCLSID(&clsid,&CLSID_FileMoniker))
879         return S_FALSE;
880
881     res = CreateBindCtx(0,&bind);
882     if (FAILED(res)) return res;
883
884     if (SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&filePath))) {
885         int result = lstrcmpiW(filePath, This->filePathName);
886         CoTaskMemFree(filePath);
887         if ( result == 0 ) return S_OK;
888     }
889     return S_FALSE;
890
891 }
892
893 /******************************************************************************
894  *        FileMoniker_Hash
895  ******************************************************************************/
896 HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
897 {
898     ICOM_THIS(FileMonikerImpl,iface);
899
900     int  h = 0,i,skip,len;
901     int  off = 0;
902     LPOLESTR val;
903
904     if (pdwHash==NULL)
905         return E_POINTER;
906
907     val =  This->filePathName;
908     len = lstrlenW(val);
909
910     if (len < 16) {
911         for (i = len ; i > 0; i--) {
912             h = (h * 37) + val[off++];
913         }
914     } else {
915         /* only sample some characters */
916         skip = len / 8;
917         for (i = len ; i > 0; i -= skip, off += skip) {
918             h = (h * 39) + val[off];
919         }
920     }
921
922     *pdwHash=h;
923
924     return S_OK;
925 }
926
927 /******************************************************************************
928  *        FileMoniker_IsRunning
929  ******************************************************************************/
930 HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,
931                                          IBindCtx* pbc,
932                                          IMoniker* pmkToLeft,
933                                          IMoniker* pmkNewlyRunning)
934 {
935     IRunningObjectTable* rot;
936     HRESULT res;
937
938     TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
939
940     if ( (pmkNewlyRunning!=NULL) && (IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK) )
941         return S_OK;
942
943     if (pbc==NULL)
944         return E_POINTER;
945
946     res=IBindCtx_GetRunningObjectTable(pbc,&rot);
947
948     if (FAILED(res))
949         return res;
950
951     res = IRunningObjectTable_IsRunning(rot,iface);
952
953     IRunningObjectTable_Release(rot);
954
955     return res;
956 }
957
958 /******************************************************************************
959  *        FileMoniker_GetTimeOfLastChange
960  ******************************************************************************/
961 HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
962                                                    IBindCtx* pbc,
963                                                    IMoniker* pmkToLeft,
964                                                    FILETIME* pFileTime)
965 {
966     ICOM_THIS(FileMonikerImpl,iface);
967     IRunningObjectTable* rot;
968     HRESULT res;
969     WIN32_FILE_ATTRIBUTE_DATA info;
970
971     TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pFileTime);
972
973     if (pFileTime==NULL)
974         return E_POINTER;
975
976     if (pmkToLeft!=NULL)
977         return E_INVALIDARG;
978
979     res=IBindCtx_GetRunningObjectTable(pbc,&rot);
980
981     if (FAILED(res))
982         return res;
983
984     res= IRunningObjectTable_GetTimeOfLastChange(rot,iface,pFileTime);
985
986     if (FAILED(res)){ /* the moniker is not registred */
987
988         if (!GetFileAttributesExW(This->filePathName,GetFileExInfoStandard,&info))
989             return MK_E_NOOBJECT;
990
991         *pFileTime=info.ftLastWriteTime;
992     }
993
994     return S_OK;
995 }
996
997 /******************************************************************************
998  *        FileMoniker_Inverse
999  ******************************************************************************/
1000 HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
1001 {
1002
1003     TRACE("(%p,%p)\n",iface,ppmk);
1004
1005     return CreateAntiMoniker(ppmk);
1006 }
1007
1008 /******************************************************************************
1009  *        FileMoniker_CommonPrefixWith
1010  ******************************************************************************/
1011 HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
1012 {
1013
1014     LPOLESTR pathThis,pathOther,*stringTable1,*stringTable2,commonPath;
1015     IBindCtx *pbind;
1016     DWORD mkSys;
1017     ULONG nb1,nb2,i,sameIdx;
1018     BOOL machimeNameCase=FALSE;
1019
1020     if (ppmkPrefix==NULL)
1021         return E_POINTER;
1022
1023     if (pmkOther==NULL)
1024         return E_INVALIDARG;
1025
1026     *ppmkPrefix=0;
1027
1028     /* check if we have the same type of moniker */
1029     IMoniker_IsSystemMoniker(pmkOther,&mkSys);
1030
1031     if(mkSys==MKSYS_FILEMONIKER){
1032         HRESULT ret;
1033
1034         CreateBindCtx(0,&pbind);
1035
1036         /* create a string based on common part of the two paths */
1037
1038         IMoniker_GetDisplayName(iface,pbind,NULL,&pathThis);
1039         IMoniker_GetDisplayName(pmkOther,pbind,NULL,&pathOther);
1040
1041         nb1=FileMonikerImpl_DecomposePath(pathThis,&stringTable1);
1042         nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2);
1043
1044         if (nb1==0 || nb2==0)
1045             return MK_E_NOPREFIX;
1046
1047         commonPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
1048
1049         *commonPath=0;
1050
1051         for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
1052                          (stringTable2[sameIdx]!=NULL) &&
1053                          (lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
1054
1055         if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
1056
1057             machimeNameCase=TRUE;
1058
1059             for(i=2;i<sameIdx;i++)
1060
1061                 if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
1062                     machimeNameCase=FALSE;
1063                     break;
1064             }
1065         }
1066
1067         if (machimeNameCase && *stringTable1[sameIdx-1]=='\\')
1068             sameIdx--;
1069
1070         if (machimeNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
1071             ret = MK_E_NOPREFIX;
1072         else
1073         {
1074             for(i=0;i<sameIdx;i++)
1075                 strcatW(commonPath,stringTable1[i]);
1076     
1077             for(i=0;i<nb1;i++)
1078                 CoTaskMemFree(stringTable1[i]);
1079     
1080             CoTaskMemFree(stringTable1);
1081     
1082             for(i=0;i<nb2;i++)
1083                 CoTaskMemFree(stringTable2[i]);
1084     
1085             CoTaskMemFree(stringTable2);
1086     
1087             ret = CreateFileMoniker(commonPath,ppmkPrefix);
1088         }
1089         HeapFree(GetProcessHeap(),0,commonPath);
1090         return ret;
1091     }
1092     else
1093         return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
1094 }
1095
1096 /******************************************************************************
1097  *        DecomposePath (local function)
1098  ******************************************************************************/
1099 int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable)
1100 {
1101     static const WCHAR bSlash[] = {'\\',0};
1102     WCHAR word[MAX_PATH];
1103     int i=0,j,tabIndex=0;
1104     LPOLESTR *strgtable ;
1105
1106     int len=lstrlenW(str);
1107
1108     TRACE("%s, %p\n", debugstr_w(str), *stringTable);
1109
1110     strgtable =CoTaskMemAlloc(len*sizeof(LPOLESTR));
1111
1112     if (strgtable==NULL)
1113         return E_OUTOFMEMORY;
1114
1115     while(str[i]!=0){
1116
1117         if(str[i]==bSlash[0]){
1118
1119             strgtable[tabIndex]=CoTaskMemAlloc(2*sizeof(WCHAR));
1120
1121             if (strgtable[tabIndex]==NULL)
1122                 return E_OUTOFMEMORY;
1123
1124             strcpyW(strgtable[tabIndex++],bSlash);
1125
1126             i++;
1127
1128         }
1129         else {
1130
1131             for(j=0; str[i]!=0 && str[i]!=bSlash[0] ; i++,j++)
1132                 word[j]=str[i];
1133
1134             word[j]=0;
1135
1136             strgtable[tabIndex]=CoTaskMemAlloc(sizeof(WCHAR)*(j+1));
1137
1138             if (strgtable[tabIndex]==NULL)
1139                 return E_OUTOFMEMORY;
1140
1141             strcpyW(strgtable[tabIndex++],word);
1142         }
1143     }
1144     strgtable[tabIndex]=NULL;
1145
1146     *stringTable=strgtable;
1147
1148     return tabIndex;
1149 }
1150
1151 /******************************************************************************
1152  *        FileMoniker_RelativePathTo
1153  ******************************************************************************/
1154 HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
1155 {
1156     IBindCtx *bind;
1157     HRESULT res;
1158     LPOLESTR str1=0,str2=0,*tabStr1=0,*tabStr2=0,relPath=0;
1159     DWORD len1=0,len2=0,sameIdx=0,j=0;
1160     static const WCHAR back[] ={'.','.','\\',0};
1161
1162     TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
1163
1164     if (ppmkRelPath==NULL)
1165         return E_POINTER;
1166
1167     if (pmOther==NULL)
1168         return E_INVALIDARG;
1169
1170     res=CreateBindCtx(0,&bind);
1171     if (FAILED(res))
1172         return res;
1173
1174     res=IMoniker_GetDisplayName(iface,bind,NULL,&str1);
1175     if (FAILED(res))
1176         return res;
1177     res=IMoniker_GetDisplayName(pmOther,bind,NULL,&str2);
1178     if (FAILED(res))
1179         return res;
1180
1181     len1=FileMonikerImpl_DecomposePath(str1,&tabStr1);
1182     len2=FileMonikerImpl_DecomposePath(str2,&tabStr2);
1183
1184     if (FAILED(len1) || FAILED(len2))
1185         return E_OUTOFMEMORY;
1186
1187     /* count the number of similar items from the begin of the two paths */
1188     for(sameIdx=0; ( (tabStr1[sameIdx]!=NULL) &&
1189                    (tabStr2[sameIdx]!=NULL) &&
1190                (lstrcmpiW(tabStr1[sameIdx],tabStr2[sameIdx])==0)); sameIdx++);
1191
1192     /* begin the construction of relativePath */
1193     /* if the two paths have a consecutive similar item from the begin ! the relativePath will be composed */
1194     /* by "..\\" in the begin */
1195     relPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(1+lstrlenW(str1)+lstrlenW(str2)));
1196
1197     *relPath=0;
1198
1199     if (len2>0 && !(len1==1 && len2==1 && sameIdx==0))
1200         for(j=sameIdx;(tabStr1[j] != NULL); j++)
1201             if (*tabStr1[j]!='\\')
1202                 strcatW(relPath,back);
1203
1204     /* add items of the second path (similar items with the first path are not included) to the relativePath */
1205     for(j=sameIdx;tabStr2[j]!=NULL;j++)
1206         strcatW(relPath,tabStr2[j]);
1207
1208     res=CreateFileMoniker(relPath,ppmkRelPath);
1209
1210     for(j=0; tabStr1[j]!=NULL;j++)
1211         CoTaskMemFree(tabStr1[j]);
1212     for(j=0; tabStr2[j]!=NULL;j++)
1213         CoTaskMemFree(tabStr2[j]);
1214     CoTaskMemFree(tabStr1);
1215     CoTaskMemFree(tabStr2);
1216     CoTaskMemFree(str1);
1217     CoTaskMemFree(str2);
1218     HeapFree(GetProcessHeap(),0,relPath);
1219
1220     if (len1==0 || len2==0 || (len1==1 && len2==1 && sameIdx==0))
1221         return MK_S_HIM;
1222
1223     return res;
1224 }
1225
1226 /******************************************************************************
1227  *        FileMoniker_GetDisplayName
1228  ******************************************************************************/
1229 HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,
1230                                               IBindCtx* pbc,
1231                                               IMoniker* pmkToLeft,
1232                                               LPOLESTR *ppszDisplayName)
1233 {
1234     ICOM_THIS(FileMonikerImpl,iface);
1235
1236     int len=lstrlenW(This->filePathName);
1237
1238     TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
1239
1240     if (ppszDisplayName==NULL)
1241         return E_POINTER;
1242
1243     if (pmkToLeft!=NULL)
1244         return E_INVALIDARG;
1245
1246     *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
1247     if (*ppszDisplayName==NULL)
1248         return E_OUTOFMEMORY;
1249
1250     strcpyW(*ppszDisplayName,This->filePathName);
1251
1252     return S_OK;
1253 }
1254
1255 /******************************************************************************
1256  *        FileMoniker_ParseDisplayName
1257  ******************************************************************************/
1258 HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,
1259                                                 IBindCtx* pbc,
1260                                                 IMoniker* pmkToLeft,
1261                                                 LPOLESTR pszDisplayName,
1262                                                 ULONG* pchEaten,
1263                                                 IMoniker** ppmkOut)
1264 {
1265     FIXME("(%p,%p,%p,%p,%p,%p),stub!\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
1266     return E_NOTIMPL;
1267 }
1268
1269 /******************************************************************************
1270  *        FileMoniker_IsSystemMoniker
1271  ******************************************************************************/
1272 HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
1273 {
1274     TRACE("(%p,%p)\n",iface,pwdMksys);
1275
1276     if (!pwdMksys)
1277         return E_POINTER;
1278
1279     (*pwdMksys)=MKSYS_FILEMONIKER;
1280
1281     return S_OK;
1282 }
1283
1284 /*******************************************************************************
1285  *        FileMonikerIROTData_QueryInterface
1286  *******************************************************************************/
1287 HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
1288 {
1289
1290     ICOM_THIS_From_IROTData(IMoniker, iface);
1291
1292     TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
1293
1294     return FileMonikerImpl_QueryInterface(This, riid, ppvObject);
1295 }
1296
1297 /***********************************************************************
1298  *        FileMonikerIROTData_AddRef
1299  */
1300 ULONG   WINAPI FileMonikerROTDataImpl_AddRef(IROTData *iface)
1301 {
1302     ICOM_THIS_From_IROTData(IMoniker, iface);
1303
1304     TRACE("(%p)\n",This);
1305
1306     return FileMonikerImpl_AddRef(This);
1307 }
1308
1309 /***********************************************************************
1310  *        FileMonikerIROTData_Release
1311  */
1312 ULONG   WINAPI FileMonikerROTDataImpl_Release(IROTData* iface)
1313 {
1314     ICOM_THIS_From_IROTData(IMoniker, iface);
1315
1316     TRACE("(%p)\n",This);
1317
1318     return FileMonikerImpl_Release(This);
1319 }
1320
1321 /******************************************************************************
1322  *        FileMonikerIROTData_GetComparaisonData
1323  ******************************************************************************/
1324 HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
1325                                                          BYTE* pbData,
1326                                                          ULONG cbMax,
1327                                                          ULONG* pcbData)
1328 {
1329     FIXME("(),stub!\n");
1330     return E_NOTIMPL;
1331 }
1332
1333 /******************************************************************************
1334  *        CreateFileMoniker (OLE32.@)
1335  ******************************************************************************/
1336 HRESULT WINAPI CreateFileMoniker(LPCOLESTR lpszPathName, LPMONIKER * ppmk)
1337 {
1338     FileMonikerImpl* newFileMoniker = 0;
1339     HRESULT  hr = E_FAIL;
1340     IID riid=IID_IMoniker;
1341
1342     TRACE("(%p,%p)\n",lpszPathName,ppmk);
1343
1344     if (ppmk==NULL)
1345         return E_POINTER;
1346
1347     if(lpszPathName==NULL)
1348         return MK_E_SYNTAX;
1349
1350     *ppmk=0;
1351
1352     newFileMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(FileMonikerImpl));
1353
1354     if (newFileMoniker == 0)
1355         return E_OUTOFMEMORY;
1356
1357     hr = FileMonikerImpl_Construct(newFileMoniker,lpszPathName);
1358
1359     if (SUCCEEDED(hr))
1360         hr = FileMonikerImpl_QueryInterface((IMoniker*)newFileMoniker,&riid,(void**)ppmk);
1361     else
1362         HeapFree(GetProcessHeap(),0,newFileMoniker);
1363
1364     return hr;
1365 }