We don't support GetDIBits with BI_RLE4/8, so for now return an
[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     WCHAR twoPoint[]={'.','.',0};
477     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
712                 return E_UNSPEC;
713             else
714
715                 return E_NOINTERFACE;
716     }
717     else {
718
719         FIXME("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
720
721         return E_NOTIMPL;
722     }
723     return res;
724 }
725
726 /******************************************************************************
727  *        FileMoniker_Reduce
728  ******************************************************************************/
729 HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,
730                                       IBindCtx* pbc,
731                                       DWORD dwReduceHowFar,
732                                       IMoniker** ppmkToLeft,
733                                       IMoniker** ppmkReduced)
734 {
735     TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
736
737     if (ppmkReduced==NULL)
738         return E_POINTER;
739
740     FileMonikerImpl_AddRef(iface);
741
742     *ppmkReduced=iface;
743
744     return MK_S_REDUCED_TO_SELF;
745 }
746 /******************************************************************************
747  *        FileMoniker_ComposeWith
748  ******************************************************************************/
749 HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,
750                                            IMoniker* pmkRight,
751                                            BOOL fOnlyIfNotGeneric,
752                                            IMoniker** ppmkComposite)
753 {
754     HRESULT res;
755     LPOLESTR str1=0,str2=0,*strDec1=0,*strDec2=0,newStr=0;
756     WCHAR twoPoint[]={'.','.',0};
757     WCHAR bkSlash[]={'\\',0};
758     IBindCtx *bind=0;
759     int i=0,j=0,lastIdx1=0,lastIdx2=0;
760     DWORD mkSys;
761
762     TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
763
764     if (ppmkComposite==NULL)
765         return E_POINTER;
766
767     if (pmkRight==NULL)
768         return E_INVALIDARG;
769
770     *ppmkComposite=0;
771
772     IMoniker_IsSystemMoniker(pmkRight,&mkSys);
773
774     /* check if we have two filemonikers to compose or not */
775     if(mkSys==MKSYS_FILEMONIKER){
776
777         CreateBindCtx(0,&bind);
778
779         FileMonikerImpl_GetDisplayName(iface,bind,NULL,&str1);
780         IMoniker_GetDisplayName(pmkRight,bind,NULL,&str2);
781
782         /* decompose pathnames of the two monikers : (to prepare the path merge operation ) */
783         lastIdx1=FileMonikerImpl_DecomposePath(str1,&strDec1)-1;
784         lastIdx2=FileMonikerImpl_DecomposePath(str2,&strDec2)-1;
785
786         if ((lastIdx1==-1 && lastIdx2>-1)||(lastIdx1==1 && lstrcmpW(strDec1[0],twoPoint)==0))
787             return MK_E_SYNTAX;
788
789         if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0)
790             lastIdx1--;
791
792         /* for etch "..\" in the left of str2 remove the right element from str1 */
793         for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ) ;i+=2){
794
795             lastIdx1-=2;
796         }
797
798         /* the length of the composed path string  is raised by the sum of the two paths lengths  */
799         newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
800
801           if (newStr==NULL)
802                 return E_OUTOFMEMORY;
803
804         /* new path is the concatenation of the rest of str1 and str2 */
805         for(*newStr=0,j=0;j<=lastIdx1;j++)
806             strcatW(newStr,strDec1[j]);
807
808         if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
809             strcatW(newStr,bkSlash);
810
811         for(j=i;j<=lastIdx2;j++)
812             strcatW(newStr,strDec2[j]);
813
814         /* create a new moniker with the new string */
815         res=CreateFileMoniker(newStr,ppmkComposite);
816
817         /* free all strings space memory used by this function */
818         HeapFree(GetProcessHeap(),0,newStr);
819
820         for(i=0; strDec1[i]!=NULL;i++)
821             CoTaskMemFree(strDec1[i]);
822         for(i=0; strDec2[i]!=NULL;i++)
823             CoTaskMemFree(strDec2[i]);
824         CoTaskMemFree(strDec1);
825         CoTaskMemFree(strDec2);
826
827         CoTaskMemFree(str1);
828         CoTaskMemFree(str2);
829
830         return res;
831     }
832     else if(mkSys==MKSYS_ANTIMONIKER){
833
834         *ppmkComposite=NULL;
835         return S_OK;
836     }
837     else if (fOnlyIfNotGeneric){
838
839         *ppmkComposite=NULL;
840         return MK_E_NEEDGENERIC;
841     }
842     else
843
844         return CreateGenericComposite(iface,pmkRight,ppmkComposite);
845 }
846
847 /******************************************************************************
848  *        FileMoniker_Enum
849  ******************************************************************************/
850 HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
851 {
852     TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
853
854     if (ppenumMoniker == NULL)
855         return E_POINTER;
856
857     *ppenumMoniker = NULL;
858
859     return S_OK;
860 }
861
862 /******************************************************************************
863  *        FileMoniker_IsEqual
864  ******************************************************************************/
865 HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
866 {
867     ICOM_THIS(FileMonikerImpl,iface);
868     CLSID clsid;
869     LPOLESTR filePath;
870     IBindCtx* bind;
871     HRESULT res;
872
873     TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
874
875     if (pmkOtherMoniker==NULL)
876         return S_FALSE;
877
878     IMoniker_GetClassID(pmkOtherMoniker,&clsid);
879
880     if (!IsEqualCLSID(&clsid,&CLSID_FileMoniker))
881         return S_FALSE;
882
883     res = CreateBindCtx(0,&bind);
884     if (FAILED(res)) return res;
885
886     if (SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&filePath))) {
887         int result = lstrcmpiW(filePath, This->filePathName);
888         CoTaskMemFree(filePath);
889         if ( result == 0 ) return S_OK;
890     }
891     return S_FALSE;
892
893 }
894
895 /******************************************************************************
896  *        FileMoniker_Hash
897  ******************************************************************************/
898 HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
899 {
900     ICOM_THIS(FileMonikerImpl,iface);
901
902     int  h = 0,i,skip,len;
903     int  off = 0;
904     LPOLESTR val;
905
906     if (pdwHash==NULL)
907         return E_POINTER;
908
909     val =  This->filePathName;
910     len = lstrlenW(val);
911
912     if (len < 16) {
913         for (i = len ; i > 0; i--) {
914             h = (h * 37) + val[off++];
915         }
916     } else {
917         /* only sample some characters */
918         skip = len / 8;
919         for (i = len ; i > 0; i -= skip, off += skip) {
920             h = (h * 39) + val[off];
921         }
922     }
923
924     *pdwHash=h;
925
926     return S_OK;
927 }
928
929 /******************************************************************************
930  *        FileMoniker_IsRunning
931  ******************************************************************************/
932 HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,
933                                          IBindCtx* pbc,
934                                          IMoniker* pmkToLeft,
935                                          IMoniker* pmkNewlyRunning)
936 {
937     IRunningObjectTable* rot;
938     HRESULT res;
939
940     TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
941
942     if ( (pmkNewlyRunning!=NULL) && (IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK) )
943         return S_OK;
944
945     if (pbc==NULL)
946         return E_POINTER;
947
948     res=IBindCtx_GetRunningObjectTable(pbc,&rot);
949
950     if (FAILED(res))
951         return res;
952
953     res = IRunningObjectTable_IsRunning(rot,iface);
954
955     IRunningObjectTable_Release(rot);
956
957     return res;
958 }
959
960 /******************************************************************************
961  *        FileMoniker_GetTimeOfLastChange
962  ******************************************************************************/
963 HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
964                                                    IBindCtx* pbc,
965                                                    IMoniker* pmkToLeft,
966                                                    FILETIME* pFileTime)
967 {
968     ICOM_THIS(FileMonikerImpl,iface);
969     IRunningObjectTable* rot;
970     HRESULT res;
971     WIN32_FILE_ATTRIBUTE_DATA info;
972
973     TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pFileTime);
974
975     if (pFileTime==NULL)
976         return E_POINTER;
977
978     if (pmkToLeft!=NULL)
979         return E_INVALIDARG;
980
981     res=IBindCtx_GetRunningObjectTable(pbc,&rot);
982
983     if (FAILED(res))
984         return res;
985
986     res= IRunningObjectTable_GetTimeOfLastChange(rot,iface,pFileTime);
987
988     if (FAILED(res)){ /* the moniker is not registred */
989
990         if (!GetFileAttributesExW(This->filePathName,GetFileExInfoStandard,&info))
991             return MK_E_NOOBJECT;
992
993         *pFileTime=info.ftLastWriteTime;
994     }
995
996     return S_OK;
997 }
998
999 /******************************************************************************
1000  *        FileMoniker_Inverse
1001  ******************************************************************************/
1002 HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
1003 {
1004
1005     TRACE("(%p,%p)\n",iface,ppmk);
1006
1007     return CreateAntiMoniker(ppmk);
1008 }
1009
1010 /******************************************************************************
1011  *        FileMoniker_CommonPrefixWith
1012  ******************************************************************************/
1013 HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
1014 {
1015
1016     LPOLESTR pathThis,pathOther,*stringTable1,*stringTable2,commonPath;
1017     IBindCtx *pbind;
1018     DWORD mkSys;
1019     ULONG nb1,nb2,i,sameIdx;
1020     BOOL machimeNameCase=FALSE;
1021
1022     if (ppmkPrefix==NULL)
1023         return E_POINTER;
1024
1025     if (pmkOther==NULL)
1026         return E_INVALIDARG;
1027
1028     *ppmkPrefix=0;
1029
1030     /* check if we have the same type of moniker */
1031     IMoniker_IsSystemMoniker(pmkOther,&mkSys);
1032
1033     if(mkSys==MKSYS_FILEMONIKER){
1034         HRESULT ret;
1035
1036         CreateBindCtx(0,&pbind);
1037
1038         /* create a string based on common part of the two paths */
1039
1040         IMoniker_GetDisplayName(iface,pbind,NULL,&pathThis);
1041         IMoniker_GetDisplayName(pmkOther,pbind,NULL,&pathOther);
1042
1043         nb1=FileMonikerImpl_DecomposePath(pathThis,&stringTable1);
1044         nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2);
1045
1046         if (nb1==0 || nb2==0)
1047             return MK_E_NOPREFIX;
1048
1049         commonPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
1050
1051         *commonPath=0;
1052
1053         for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
1054                          (stringTable2[sameIdx]!=NULL) &&
1055                          (lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
1056
1057         if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
1058
1059             machimeNameCase=TRUE;
1060
1061             for(i=2;i<sameIdx;i++)
1062
1063                 if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
1064                     machimeNameCase=FALSE;
1065                     break;
1066             }
1067         }
1068
1069         if (machimeNameCase && *stringTable1[sameIdx-1]=='\\')
1070             sameIdx--;
1071
1072         if (machimeNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
1073             ret = MK_E_NOPREFIX;
1074         else
1075         {
1076             for(i=0;i<sameIdx;i++)
1077                 strcatW(commonPath,stringTable1[i]);
1078     
1079             for(i=0;i<nb1;i++)
1080                 CoTaskMemFree(stringTable1[i]);
1081     
1082             CoTaskMemFree(stringTable1);
1083     
1084             for(i=0;i<nb2;i++)
1085                 CoTaskMemFree(stringTable2[i]);
1086     
1087             CoTaskMemFree(stringTable2);
1088     
1089             ret = CreateFileMoniker(commonPath,ppmkPrefix);
1090         }
1091         HeapFree(GetProcessHeap(),0,commonPath);
1092         return ret;
1093     }
1094     else
1095         return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
1096 }
1097
1098 /******************************************************************************
1099  *        DecomposePath (local function)
1100  ******************************************************************************/
1101 int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable)
1102 {
1103     WCHAR bSlash[] = {'\\',0};
1104     WCHAR word[MAX_PATH];
1105     int i=0,j,tabIndex=0;
1106     LPOLESTR *strgtable ;
1107
1108     int len=lstrlenW(str);
1109
1110     TRACE("%s, %p\n", debugstr_w(str), *stringTable);
1111
1112     strgtable =CoTaskMemAlloc(len*sizeof(LPOLESTR));
1113
1114     if (strgtable==NULL)
1115         return E_OUTOFMEMORY;
1116
1117     while(str[i]!=0){
1118
1119         if(str[i]==bSlash[0]){
1120
1121             strgtable[tabIndex]=CoTaskMemAlloc(2*sizeof(WCHAR));
1122
1123             if (strgtable[tabIndex]==NULL)
1124                 return E_OUTOFMEMORY;
1125
1126             strcpyW(strgtable[tabIndex++],bSlash);
1127
1128             i++;
1129
1130         }
1131         else {
1132
1133             for(j=0; str[i]!=0 && str[i]!=bSlash[0] ; i++,j++)
1134                 word[j]=str[i];
1135
1136             word[j]=0;
1137
1138             strgtable[tabIndex]=CoTaskMemAlloc(sizeof(WCHAR)*(j+1));
1139
1140             if (strgtable[tabIndex]==NULL)
1141                 return E_OUTOFMEMORY;
1142
1143             strcpyW(strgtable[tabIndex++],word);
1144         }
1145     }
1146     strgtable[tabIndex]=NULL;
1147
1148     *stringTable=strgtable;
1149
1150     return tabIndex;
1151 }
1152
1153 /******************************************************************************
1154  *        FileMoniker_RelativePathTo
1155  ******************************************************************************/
1156 HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
1157 {
1158     IBindCtx *bind;
1159     HRESULT res;
1160     LPOLESTR str1=0,str2=0,*tabStr1=0,*tabStr2=0,relPath=0;
1161     DWORD len1=0,len2=0,sameIdx=0,j=0;
1162     WCHAR back[] ={'.','.','\\',0};
1163
1164     TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
1165
1166     if (ppmkRelPath==NULL)
1167         return E_POINTER;
1168
1169     if (pmOther==NULL)
1170         return E_INVALIDARG;
1171
1172     res=CreateBindCtx(0,&bind);
1173     if (FAILED(res))
1174         return res;
1175
1176     res=IMoniker_GetDisplayName(iface,bind,NULL,&str1);
1177     if (FAILED(res))
1178         return res;
1179     res=IMoniker_GetDisplayName(pmOther,bind,NULL,&str2);
1180     if (FAILED(res))
1181         return res;
1182
1183     len1=FileMonikerImpl_DecomposePath(str1,&tabStr1);
1184     len2=FileMonikerImpl_DecomposePath(str2,&tabStr2);
1185
1186     if (FAILED(len1) || FAILED(len2))
1187         return E_OUTOFMEMORY;
1188
1189     /* count the number of similar items from the begin of the two paths */
1190     for(sameIdx=0; ( (tabStr1[sameIdx]!=NULL) &&
1191                    (tabStr2[sameIdx]!=NULL) &&
1192                (lstrcmpiW(tabStr1[sameIdx],tabStr2[sameIdx])==0)); sameIdx++);
1193
1194     /* begin the construction of relativePath */
1195     /* if the two paths have a consecutive similar item from the begin ! the relativePath will be composed */
1196     /* by "..\\" in the begin */
1197     relPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(1+lstrlenW(str1)+lstrlenW(str2)));
1198
1199     *relPath=0;
1200
1201     if (len2>0 && !(len1==1 && len2==1 && sameIdx==0))
1202         for(j=sameIdx;(tabStr1[j] != NULL); j++)
1203             if (*tabStr1[j]!='\\')
1204                 strcatW(relPath,back);
1205
1206     /* add items of the second path (similar items with the first path are not included) to the relativePath */
1207     for(j=sameIdx;tabStr2[j]!=NULL;j++)
1208         strcatW(relPath,tabStr2[j]);
1209
1210     res=CreateFileMoniker(relPath,ppmkRelPath);
1211
1212     for(j=0; tabStr1[j]!=NULL;j++)
1213         CoTaskMemFree(tabStr1[j]);
1214     for(j=0; tabStr2[j]!=NULL;j++)
1215         CoTaskMemFree(tabStr2[j]);
1216     CoTaskMemFree(tabStr1);
1217     CoTaskMemFree(tabStr2);
1218     CoTaskMemFree(str1);
1219     CoTaskMemFree(str2);
1220     HeapFree(GetProcessHeap(),0,relPath);
1221
1222     if (len1==0 || len2==0 || (len1==1 && len2==1 && sameIdx==0))
1223         return MK_S_HIM;
1224
1225     return res;
1226 }
1227
1228 /******************************************************************************
1229  *        FileMoniker_GetDisplayName
1230  ******************************************************************************/
1231 HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,
1232                                               IBindCtx* pbc,
1233                                               IMoniker* pmkToLeft,
1234                                               LPOLESTR *ppszDisplayName)
1235 {
1236     ICOM_THIS(FileMonikerImpl,iface);
1237
1238     int len=lstrlenW(This->filePathName);
1239
1240     TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
1241
1242     if (ppszDisplayName==NULL)
1243         return E_POINTER;
1244
1245     if (pmkToLeft!=NULL)
1246         return E_INVALIDARG;
1247
1248     *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
1249     if (*ppszDisplayName==NULL)
1250         return E_OUTOFMEMORY;
1251
1252     strcpyW(*ppszDisplayName,This->filePathName);
1253
1254     return S_OK;
1255 }
1256
1257 /******************************************************************************
1258  *        FileMoniker_ParseDisplayName
1259  ******************************************************************************/
1260 HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,
1261                                                 IBindCtx* pbc,
1262                                                 IMoniker* pmkToLeft,
1263                                                 LPOLESTR pszDisplayName,
1264                                                 ULONG* pchEaten,
1265                                                 IMoniker** ppmkOut)
1266 {
1267     FIXME("(%p,%p,%p,%p,%p,%p),stub!\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
1268     return E_NOTIMPL;
1269 }
1270
1271 /******************************************************************************
1272  *        FileMoniker_IsSystemMoniker
1273  ******************************************************************************/
1274 HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
1275 {
1276     TRACE("(%p,%p)\n",iface,pwdMksys);
1277
1278     if (!pwdMksys)
1279         return E_POINTER;
1280
1281     (*pwdMksys)=MKSYS_FILEMONIKER;
1282
1283     return S_OK;
1284 }
1285
1286 /*******************************************************************************
1287  *        FileMonikerIROTData_QueryInterface
1288  *******************************************************************************/
1289 HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
1290 {
1291
1292     ICOM_THIS_From_IROTData(IMoniker, iface);
1293
1294     TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
1295
1296     return FileMonikerImpl_QueryInterface(This, riid, ppvObject);
1297 }
1298
1299 /***********************************************************************
1300  *        FileMonikerIROTData_AddRef
1301  */
1302 ULONG   WINAPI FileMonikerROTDataImpl_AddRef(IROTData *iface)
1303 {
1304     ICOM_THIS_From_IROTData(IMoniker, iface);
1305
1306     TRACE("(%p)\n",This);
1307
1308     return FileMonikerImpl_AddRef(This);
1309 }
1310
1311 /***********************************************************************
1312  *        FileMonikerIROTData_Release
1313  */
1314 ULONG   WINAPI FileMonikerROTDataImpl_Release(IROTData* iface)
1315 {
1316     ICOM_THIS_From_IROTData(IMoniker, iface);
1317
1318     TRACE("(%p)\n",This);
1319
1320     return FileMonikerImpl_Release(This);
1321 }
1322
1323 /******************************************************************************
1324  *        FileMonikerIROTData_GetComparaisonData
1325  ******************************************************************************/
1326 HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
1327                                                          BYTE* pbData,
1328                                                          ULONG cbMax,
1329                                                          ULONG* pcbData)
1330 {
1331     FIXME("(),stub!\n");
1332     return E_NOTIMPL;
1333 }
1334
1335 /******************************************************************************
1336  *        CreateFileMoniker (OLE32.@)
1337  ******************************************************************************/
1338 HRESULT WINAPI CreateFileMoniker(LPCOLESTR lpszPathName, LPMONIKER * ppmk)
1339 {
1340     FileMonikerImpl* newFileMoniker = 0;
1341     HRESULT  hr = E_FAIL;
1342     IID riid=IID_IMoniker;
1343
1344     TRACE("(%p,%p)\n",lpszPathName,ppmk);
1345
1346     if (ppmk==NULL)
1347         return E_POINTER;
1348
1349     if(lpszPathName==NULL)
1350         return MK_E_SYNTAX;
1351
1352     *ppmk=0;
1353
1354     newFileMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(FileMonikerImpl));
1355
1356     if (newFileMoniker == 0)
1357         return E_OUTOFMEMORY;
1358
1359     hr = FileMonikerImpl_Construct(newFileMoniker,lpszPathName);
1360
1361     if (SUCCEEDED(hr))
1362         hr = FileMonikerImpl_QueryInterface((IMoniker*)newFileMoniker,&riid,(void**)ppmk);
1363     else
1364         HeapFree(GetProcessHeap(),0,newFileMoniker);
1365
1366     return hr;
1367 }