Get rid of the non-standard ICOM_THIS macro.
[wine.git] / dlls / ole32 / filemoniker.c
blobc465507ec7f023d25a386d912bab91dd97106c16
1 /***************************************************************************************
2 * FileMonikers implementation
4 * Copyright 1999 Noomen Hamza
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.
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.
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 ***************************************************************************************/
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <string.h>
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"
36 #include "compobj_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ole);
40 const CLSID CLSID_FileMoniker = {
41 0x303, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
44 /* filemoniker data structure */
45 typedef struct FileMonikerImpl{
47 IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/
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.
52 IROTDataVtbl* lpvtbl2; /* VTable relative to the IROTData interface.*/
54 ULONG ref; /* reference counter for this object */
56 LPOLESTR filePathName; /* path string identified by this filemoniker */
58 } FileMonikerImpl;
60 /********************************************************************************/
61 /* FileMoniker prototype functions : */
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);
68 /* IPersist prototype functions */
69 static HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
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);
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);
94 /********************************************************************************/
95 /* IROTData prototype functions */
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);
102 /* IROTData prototype function */
103 static HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
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);
111 /********************************************************************************/
112 /* Virtual function table for the FileMonikerImpl class which include IPersist,*/
113 /* IPersistStream and IMoniker functions. */
114 static IMonikerVtbl VT_FileMonikerImpl =
116 FileMonikerImpl_QueryInterface,
117 FileMonikerImpl_AddRef,
118 FileMonikerImpl_Release,
119 FileMonikerImpl_GetClassID,
120 FileMonikerImpl_IsDirty,
121 FileMonikerImpl_Load,
122 FileMonikerImpl_Save,
123 FileMonikerImpl_GetSizeMax,
124 FileMonikerImpl_BindToObject,
125 FileMonikerImpl_BindToStorage,
126 FileMonikerImpl_Reduce,
127 FileMonikerImpl_ComposeWith,
128 FileMonikerImpl_Enum,
129 FileMonikerImpl_IsEqual,
130 FileMonikerImpl_Hash,
131 FileMonikerImpl_IsRunning,
132 FileMonikerImpl_GetTimeOfLastChange,
133 FileMonikerImpl_Inverse,
134 FileMonikerImpl_CommonPrefixWith,
135 FileMonikerImpl_RelativePathTo,
136 FileMonikerImpl_GetDisplayName,
137 FileMonikerImpl_ParseDisplayName,
138 FileMonikerImpl_IsSystemMoniker
141 /********************************************************************************/
142 /* Virtual function table for the IROTData class. */
143 static IROTDataVtbl VT_ROTDataImpl =
145 FileMonikerROTDataImpl_QueryInterface,
146 FileMonikerROTDataImpl_AddRef,
147 FileMonikerROTDataImpl_Release,
148 FileMonikerROTDataImpl_GetComparaisonData
151 /*******************************************************************************
152 * FileMoniker_QueryInterface
153 *******************************************************************************/
154 HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
156 FileMonikerImpl *This = (FileMonikerImpl *)iface;
158 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
160 /* Perform a sanity check on the parameters.*/
161 if ( (This==0) || (ppvObject==0) )
162 return E_INVALIDARG;
164 /* Initialize the return parameter */
165 *ppvObject = 0;
167 /* Compare the riid with the interface IDs implemented by this object.*/
168 if (IsEqualIID(&IID_IUnknown, riid) ||
169 IsEqualIID(&IID_IPersist, riid) ||
170 IsEqualIID(&IID_IPersistStream,riid) ||
171 IsEqualIID(&IID_IMoniker, riid)
173 *ppvObject = iface;
175 else if (IsEqualIID(&IID_IROTData, riid))
176 *ppvObject = (IROTData*)&(This->lpvtbl2);
178 /* Check that we obtained an interface.*/
179 if ((*ppvObject)==0)
180 return E_NOINTERFACE;
182 /* Query Interface always increases the reference count by one when it is successful */
183 FileMonikerImpl_AddRef(iface);
185 return S_OK;
188 /******************************************************************************
189 * FileMoniker_AddRef
190 ******************************************************************************/
191 ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface)
193 FileMonikerImpl *This = (FileMonikerImpl *)iface;
195 TRACE("(%p)\n",iface);
197 return ++(This->ref);
200 /******************************************************************************
201 * FileMoniker_Release
202 ******************************************************************************/
203 ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface)
205 FileMonikerImpl *This = (FileMonikerImpl *)iface;
207 TRACE("(%p)\n",iface);
209 This->ref--;
211 /* destroy the object if there's no more reference on it */
212 if (This->ref==0){
214 FileMonikerImpl_Destroy(This);
216 return 0;
218 return This->ref;
221 /******************************************************************************
222 * FileMoniker_GetClassID
223 ******************************************************************************/
224 HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface,
225 CLSID *pClassID)/* Pointer to CLSID of object */
227 TRACE("(%p,%p),stub!\n",iface,pClassID);
229 if (pClassID==NULL)
230 return E_POINTER;
232 *pClassID = CLSID_FileMoniker;
234 return S_OK;
237 /******************************************************************************
238 * FileMoniker_IsDirty
239 ******************************************************************************/
240 HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface)
242 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
243 method in the OLE-provided moniker interfaces always return S_FALSE because
244 their internal state never changes. */
246 TRACE("(%p)\n",iface);
248 return S_FALSE;
251 /******************************************************************************
252 * FileMoniker_Load
253 ******************************************************************************/
254 HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface,IStream* pStm)
256 HRESULT res;
257 CHAR* filePathA;
258 WCHAR* filePathW;
259 ULONG bread;
260 WORD wbuffer;
261 DWORD dwbuffer,length,i,doubleLenHex,doubleLenDec;
263 FileMonikerImpl *This = (FileMonikerImpl *)iface;
265 TRACE("(%p,%p)\n",iface,pStm);
267 /* this function locates and reads from the stream the filePath string written by FileMonikerImpl_Save */
269 /* first WORD is non significative */
270 res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
271 if (bread!=sizeof(WORD) || wbuffer!=0)
272 return E_FAIL;
274 /* read filePath string length (plus one) */
275 res=IStream_Read(pStm,&length,sizeof(DWORD),&bread);
276 if (bread != sizeof(DWORD))
277 return E_FAIL;
279 /* read filePath string */
280 filePathA=HeapAlloc(GetProcessHeap(),0,length);
281 res=IStream_Read(pStm,filePathA,length,&bread);
282 HeapFree(GetProcessHeap(),0,filePathA);
283 if (bread != length)
284 return E_FAIL;
286 /* read the first constant */
287 IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
288 if (bread != sizeof(DWORD) || dwbuffer != 0xDEADFFFF)
289 return E_FAIL;
291 length--;
293 for(i=0;i<10;i++){
294 res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
295 if (bread!=sizeof(WORD) || wbuffer!=0)
296 return E_FAIL;
299 if (length>8)
300 length=0;
302 doubleLenHex=doubleLenDec=2*length;
303 if (length > 5)
304 doubleLenDec+=6;
306 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
307 if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenDec)
308 return E_FAIL;
310 if (length==0)
311 return res;
313 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
314 if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenHex)
315 return E_FAIL;
317 res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
318 if (bread!=sizeof(WORD) || wbuffer!=0x3)
319 return E_FAIL;
321 filePathW=HeapAlloc(GetProcessHeap(),0,(length+1)*sizeof(WCHAR));
322 filePathW[length]=0;
323 res=IStream_Read(pStm,filePathW,doubleLenHex,&bread);
324 if (bread!=doubleLenHex) {
325 HeapFree(GetProcessHeap(), 0, filePathW);
326 return E_FAIL;
329 if (This->filePathName!=NULL)
330 HeapFree(GetProcessHeap(),0,This->filePathName);
332 This->filePathName=filePathW;
334 return res;
337 /******************************************************************************
338 * FileMoniker_Save
339 ******************************************************************************/
340 HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface,
341 IStream* pStm,/* pointer to the stream where the object is to be saved */
342 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
344 /* this function saves data of this object. In the beginning I thougth
345 * that I have just to write the filePath string on Stream. But, when I
346 * tested this function whith windows programs samples, I noticed that it
347 * was not the case. So I analysed data written by this function on
348 * Windows and what this did function exactly ! But I have no idea about
349 * its logic !
350 * I guessed data which must be written on stream is:
351 * 1) WORD constant:zero
352 * 2) length of the path string ("\0" included)
353 * 3) path string type A
354 * 4) DWORD constant : 0xDEADFFFF
355 * 5) ten WORD constant: zero
356 * 6) DWORD: double-length of the the path string type W ("\0" not
357 * included)
358 * 7) WORD constant: 0x3
359 * 8) filePath unicode string.
360 * if the length(filePath) > 8 or length(filePath) == 8 stop at step 5)
363 FileMonikerImpl *This = (FileMonikerImpl *)iface;
365 HRESULT res;
366 LPOLESTR filePathW=This->filePathName;
367 CHAR* filePathA;
368 DWORD len;
370 DWORD constant1 = 0xDEADFFFF; /* these constants are detected after analysing the data structure written by */
371 WORD constant2 = 0x3; /* FileMoniker_Save function in a windows program system */
373 WORD zero=0;
374 DWORD doubleLenHex;
375 DWORD doubleLenDec;
376 int i=0;
378 TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty);
380 if (pStm==NULL)
381 return E_POINTER;
383 /* write a DWORD set to 0 : constant */
384 res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
386 /* write length of filePath string ( "\0" included )*/
387 len = WideCharToMultiByte( CP_ACP, 0, filePathW, -1, NULL, 0, NULL, NULL );
388 res=IStream_Write(pStm,&len,sizeof(DWORD),NULL);
390 /* write filePath string type A */
391 filePathA=HeapAlloc(GetProcessHeap(),0,len);
392 WideCharToMultiByte( CP_ACP, 0, filePathW, -1, filePathA, len, NULL, NULL );
393 res=IStream_Write(pStm,filePathA,len,NULL);
394 HeapFree(GetProcessHeap(),0,filePathA);
396 /* write a DWORD set to 0xDEADFFFF: constant */
397 res=IStream_Write(pStm,&constant1,sizeof(DWORD),NULL);
399 len--;
400 /* write 10 times a DWORD set to 0 : constants */
401 for(i=0;i<10;i++)
402 res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
404 if (len>8)
405 len=0;
407 doubleLenHex=doubleLenDec=2*len;
408 if (len > 5)
409 doubleLenDec+=6;
411 /* write double-length of the path string ( "\0" included )*/
412 res=IStream_Write(pStm,&doubleLenDec,sizeof(DWORD),NULL);
414 if (len==0)
415 return res;
417 /* write double-length (hexa representation) of the path string ( "\0" included ) */
418 res=IStream_Write(pStm,&doubleLenHex,sizeof(DWORD),NULL);
420 /* write a WORD set to 0x3: constant */
421 res=IStream_Write(pStm,&constant2,sizeof(WORD),NULL);
423 /* write path unicode string */
424 res=IStream_Write(pStm,filePathW,doubleLenHex,NULL);
426 return res;
429 /******************************************************************************
430 * FileMoniker_GetSizeMax
431 ******************************************************************************/
432 HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface,
433 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
435 FileMonikerImpl *This = (FileMonikerImpl *)iface;
436 DWORD len=lstrlenW(This->filePathName);
437 DWORD sizeMAx;
439 TRACE("(%p,%p)\n",iface,pcbSize);
441 if (pcbSize!=NULL)
442 return E_POINTER;
444 /* for more details see FileMonikerImpl_Save coments */
446 sizeMAx = sizeof(WORD) + /* first WORD is 0 */
447 sizeof(DWORD)+ /* length of filePath including "\0" in the end of the string */
448 (len+1)+ /* filePath string */
449 sizeof(DWORD)+ /* constant : 0xDEADFFFF */
450 10*sizeof(WORD)+ /* 10 zero WORD */
451 sizeof(DWORD); /* size of the unicode filePath: "\0" not included */
453 if (len==0 || len > 8)
454 return S_OK;
456 sizeMAx += sizeof(DWORD)+ /* size of the unicode filePath: "\0" not included */
457 sizeof(WORD)+ /* constant : 0x3 */
458 len*sizeof(WCHAR); /* unicde filePath string */
460 pcbSize->u.LowPart=sizeMAx;
461 pcbSize->u.HighPart=0;
463 return S_OK;
466 /******************************************************************************
467 * FileMoniker_Construct (local function)
468 *******************************************************************************/
469 HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* This, LPCOLESTR lpszPathName)
471 int nb=0,i;
472 int sizeStr=lstrlenW(lpszPathName);
473 LPOLESTR *tabStr=0;
474 static const WCHAR twoPoint[]={'.','.',0};
475 static const WCHAR bkSlash[]={'\\',0};
476 BYTE addBkSlash;
478 TRACE("(%p,%p)\n",This,lpszPathName);
480 /* Initialize the virtual fgunction table. */
481 This->lpvtbl1 = &VT_FileMonikerImpl;
482 This->lpvtbl2 = &VT_ROTDataImpl;
483 This->ref = 0;
485 This->filePathName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1));
487 if (This->filePathName==NULL)
488 return E_OUTOFMEMORY;
490 strcpyW(This->filePathName,lpszPathName);
492 nb=FileMonikerImpl_DecomposePath(This->filePathName,&tabStr);
494 if (nb > 0 ){
496 addBkSlash=1;
497 if (lstrcmpW(tabStr[0],twoPoint)!=0)
498 addBkSlash=0;
499 else
500 for(i=0;i<nb;i++){
502 if ( (lstrcmpW(tabStr[i],twoPoint)!=0) && (lstrcmpW(tabStr[i],bkSlash)!=0) ){
503 addBkSlash=0;
504 break;
506 else
508 if (lstrcmpW(tabStr[i],bkSlash)==0 && i<nb-1 && lstrcmpW(tabStr[i+1],bkSlash)==0){
509 *tabStr[i]=0;
510 sizeStr--;
511 addBkSlash=0;
512 break;
516 if (lstrcmpW(tabStr[nb-1],bkSlash)==0)
517 addBkSlash=0;
519 This->filePathName=HeapReAlloc(GetProcessHeap(),0,This->filePathName,(sizeStr+1)*sizeof(WCHAR));
521 *This->filePathName=0;
523 for(i=0;tabStr[i]!=NULL;i++)
524 strcatW(This->filePathName,tabStr[i]);
526 if (addBkSlash)
527 strcatW(This->filePathName,bkSlash);
530 for(i=0; tabStr[i]!=NULL;i++)
531 CoTaskMemFree(tabStr[i]);
532 CoTaskMemFree(tabStr);
534 return S_OK;
537 /******************************************************************************
538 * FileMoniker_Destroy (local function)
539 *******************************************************************************/
540 HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* This)
542 TRACE("(%p)\n",This);
544 if (This->filePathName!=NULL)
545 HeapFree(GetProcessHeap(),0,This->filePathName);
547 HeapFree(GetProcessHeap(),0,This);
549 return S_OK;
552 /******************************************************************************
553 * FileMoniker_BindToObject
554 ******************************************************************************/
555 HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,
556 IBindCtx* pbc,
557 IMoniker* pmkToLeft,
558 REFIID riid,
559 VOID** ppvResult)
561 HRESULT res=E_FAIL;
562 CLSID clsID;
563 IUnknown* pObj=0;
564 IRunningObjectTable *prot=0;
565 IPersistFile *ppf=0;
566 IClassFactory *pcf=0;
567 IClassActivator *pca=0;
569 FileMonikerImpl *This = (FileMonikerImpl *)iface;
571 *ppvResult=0;
573 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
575 if(pmkToLeft==NULL){
577 res=IBindCtx_GetRunningObjectTable(pbc,&prot);
579 if (SUCCEEDED(res)){
580 /* if the requested class was loaded before ! we don't need to reload it */
581 res = IRunningObjectTable_GetObject(prot,iface,&pObj);
583 if (res==S_FALSE){
584 /* first activation of this class */
585 res=GetClassFile(This->filePathName,&clsID);
586 if (SUCCEEDED(res)){
588 res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IPersistFile,(void**)&ppf);
589 if (SUCCEEDED(res)){
591 res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
592 if (SUCCEEDED(res)){
594 pObj=(IUnknown*)ppf;
595 IUnknown_AddRef(pObj);
602 else{
603 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassFactory,(void**)&pcf);
605 if (res==E_NOINTERFACE){
607 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassActivator,(void**)&pca);
609 if (res==E_NOINTERFACE)
610 return MK_E_INTERMEDIATEINTERFACENOTSUPPORTED;
612 if (pcf!=NULL){
614 IClassFactory_CreateInstance(pcf,NULL,&IID_IPersistFile,(void**)ppf);
616 res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
618 if (SUCCEEDED(res)){
620 pObj=(IUnknown*)ppf;
621 IUnknown_AddRef(pObj);
624 if (pca!=NULL){
626 FIXME("()\n");
628 /*res=GetClassFile(This->filePathName,&clsID);
630 if (SUCCEEDED(res)){
632 res=IClassActivator_GetClassObject(pca,&clsID,CLSCTX_ALL,0,&IID_IPersistFile,(void**)&ppf);
634 if (SUCCEEDED(res)){
636 pObj=(IUnknown*)ppf;
637 IUnknown_AddRef(pObj);
643 if (pObj!=NULL){
644 /* get the requested interface from the loaded class */
645 res= IUnknown_QueryInterface(pObj,riid,ppvResult);
647 IBindCtx_RegisterObjectBound(pbc,(IUnknown*)*ppvResult);
649 IUnknown_Release(pObj);
652 if (prot!=NULL)
653 IRunningObjectTable_Release(prot);
655 if (ppf!=NULL)
656 IPersistFile_Release(ppf);
658 if (pca!=NULL)
659 IClassActivator_Release(pca);
661 if (pcf!=NULL)
662 IClassFactory_Release(pcf);
664 return res;
667 /******************************************************************************
668 * FileMoniker_BindToStorage
669 ******************************************************************************/
670 HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,
671 IBindCtx* pbc,
672 IMoniker* pmkToLeft,
673 REFIID riid,
674 VOID** ppvObject)
676 LPOLESTR filePath=0;
677 IStorage *pstg=0;
678 HRESULT res;
680 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
682 if (pmkToLeft==NULL){
684 if (IsEqualIID(&IID_IStorage, riid)){
686 /* get the file name */
687 FileMonikerImpl_GetDisplayName(iface,pbc,pmkToLeft,&filePath);
689 /* verifie if the file contains a storage object */
690 res=StgIsStorageFile(filePath);
692 if(res==S_OK){
694 res=StgOpenStorage(filePath,NULL,STGM_READWRITE|STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
696 if (SUCCEEDED(res)){
698 *ppvObject=pstg;
700 IStorage_AddRef(pstg);
702 return res;
705 CoTaskMemFree(filePath);
707 else
708 if ( (IsEqualIID(&IID_IStream, riid)) || (IsEqualIID(&IID_ILockBytes, riid)) )
709 return E_FAIL;
710 else
711 return E_NOINTERFACE;
713 else {
715 FIXME("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
717 return E_NOTIMPL;
719 return res;
722 /******************************************************************************
723 * FileMoniker_Reduce
724 ******************************************************************************/
725 HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,
726 IBindCtx* pbc,
727 DWORD dwReduceHowFar,
728 IMoniker** ppmkToLeft,
729 IMoniker** ppmkReduced)
731 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
733 if (ppmkReduced==NULL)
734 return E_POINTER;
736 FileMonikerImpl_AddRef(iface);
738 *ppmkReduced=iface;
740 return MK_S_REDUCED_TO_SELF;
742 /******************************************************************************
743 * FileMoniker_ComposeWith
744 ******************************************************************************/
745 HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,
746 IMoniker* pmkRight,
747 BOOL fOnlyIfNotGeneric,
748 IMoniker** ppmkComposite)
750 HRESULT res;
751 LPOLESTR str1=0,str2=0,*strDec1=0,*strDec2=0,newStr=0;
752 static const WCHAR twoPoint[]={'.','.',0};
753 static const WCHAR bkSlash[]={'\\',0};
754 IBindCtx *bind=0;
755 int i=0,j=0,lastIdx1=0,lastIdx2=0;
756 DWORD mkSys;
758 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
760 if (ppmkComposite==NULL)
761 return E_POINTER;
763 if (pmkRight==NULL)
764 return E_INVALIDARG;
766 *ppmkComposite=0;
768 IMoniker_IsSystemMoniker(pmkRight,&mkSys);
770 /* check if we have two filemonikers to compose or not */
771 if(mkSys==MKSYS_FILEMONIKER){
773 CreateBindCtx(0,&bind);
775 FileMonikerImpl_GetDisplayName(iface,bind,NULL,&str1);
776 IMoniker_GetDisplayName(pmkRight,bind,NULL,&str2);
778 /* decompose pathnames of the two monikers : (to prepare the path merge operation ) */
779 lastIdx1=FileMonikerImpl_DecomposePath(str1,&strDec1)-1;
780 lastIdx2=FileMonikerImpl_DecomposePath(str2,&strDec2)-1;
782 if ((lastIdx1==-1 && lastIdx2>-1)||(lastIdx1==1 && lstrcmpW(strDec1[0],twoPoint)==0))
783 return MK_E_SYNTAX;
785 if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0)
786 lastIdx1--;
788 /* for etch "..\" in the left of str2 remove the right element from str1 */
789 for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ) ;i+=2){
791 lastIdx1-=2;
794 /* the length of the composed path string is raised by the sum of the two paths lengths */
795 newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
797 if (newStr==NULL)
798 return E_OUTOFMEMORY;
800 /* new path is the concatenation of the rest of str1 and str2 */
801 for(*newStr=0,j=0;j<=lastIdx1;j++)
802 strcatW(newStr,strDec1[j]);
804 if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
805 strcatW(newStr,bkSlash);
807 for(j=i;j<=lastIdx2;j++)
808 strcatW(newStr,strDec2[j]);
810 /* create a new moniker with the new string */
811 res=CreateFileMoniker(newStr,ppmkComposite);
813 /* free all strings space memory used by this function */
814 HeapFree(GetProcessHeap(),0,newStr);
816 for(i=0; strDec1[i]!=NULL;i++)
817 CoTaskMemFree(strDec1[i]);
818 for(i=0; strDec2[i]!=NULL;i++)
819 CoTaskMemFree(strDec2[i]);
820 CoTaskMemFree(strDec1);
821 CoTaskMemFree(strDec2);
823 CoTaskMemFree(str1);
824 CoTaskMemFree(str2);
826 return res;
828 else if(mkSys==MKSYS_ANTIMONIKER){
830 *ppmkComposite=NULL;
831 return S_OK;
833 else if (fOnlyIfNotGeneric){
835 *ppmkComposite=NULL;
836 return MK_E_NEEDGENERIC;
838 else
840 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
843 /******************************************************************************
844 * FileMoniker_Enum
845 ******************************************************************************/
846 HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
848 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
850 if (ppenumMoniker == NULL)
851 return E_POINTER;
853 *ppenumMoniker = NULL;
855 return S_OK;
858 /******************************************************************************
859 * FileMoniker_IsEqual
860 ******************************************************************************/
861 HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
863 FileMonikerImpl *This = (FileMonikerImpl *)iface;
864 CLSID clsid;
865 LPOLESTR filePath;
866 IBindCtx* bind;
867 HRESULT res;
869 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
871 if (pmkOtherMoniker==NULL)
872 return S_FALSE;
874 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
876 if (!IsEqualCLSID(&clsid,&CLSID_FileMoniker))
877 return S_FALSE;
879 res = CreateBindCtx(0,&bind);
880 if (FAILED(res)) return res;
882 if (SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&filePath))) {
883 int result = lstrcmpiW(filePath, This->filePathName);
884 CoTaskMemFree(filePath);
885 if ( result == 0 ) return S_OK;
887 return S_FALSE;
891 /******************************************************************************
892 * FileMoniker_Hash
893 ******************************************************************************/
894 HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
896 FileMonikerImpl *This = (FileMonikerImpl *)iface;
898 int h = 0,i,skip,len;
899 int off = 0;
900 LPOLESTR val;
902 if (pdwHash==NULL)
903 return E_POINTER;
905 val = This->filePathName;
906 len = lstrlenW(val);
908 if (len < 16) {
909 for (i = len ; i > 0; i--) {
910 h = (h * 37) + val[off++];
912 } else {
913 /* only sample some characters */
914 skip = len / 8;
915 for (i = len ; i > 0; i -= skip, off += skip) {
916 h = (h * 39) + val[off];
920 *pdwHash=h;
922 return S_OK;
925 /******************************************************************************
926 * FileMoniker_IsRunning
927 ******************************************************************************/
928 HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,
929 IBindCtx* pbc,
930 IMoniker* pmkToLeft,
931 IMoniker* pmkNewlyRunning)
933 IRunningObjectTable* rot;
934 HRESULT res;
936 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
938 if ( (pmkNewlyRunning!=NULL) && (IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK) )
939 return S_OK;
941 if (pbc==NULL)
942 return E_POINTER;
944 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
946 if (FAILED(res))
947 return res;
949 res = IRunningObjectTable_IsRunning(rot,iface);
951 IRunningObjectTable_Release(rot);
953 return res;
956 /******************************************************************************
957 * FileMoniker_GetTimeOfLastChange
958 ******************************************************************************/
959 HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
960 IBindCtx* pbc,
961 IMoniker* pmkToLeft,
962 FILETIME* pFileTime)
964 FileMonikerImpl *This = (FileMonikerImpl *)iface;
965 IRunningObjectTable* rot;
966 HRESULT res;
967 WIN32_FILE_ATTRIBUTE_DATA info;
969 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pFileTime);
971 if (pFileTime==NULL)
972 return E_POINTER;
974 if (pmkToLeft!=NULL)
975 return E_INVALIDARG;
977 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
979 if (FAILED(res))
980 return res;
982 res= IRunningObjectTable_GetTimeOfLastChange(rot,iface,pFileTime);
984 if (FAILED(res)){ /* the moniker is not registered */
986 if (!GetFileAttributesExW(This->filePathName,GetFileExInfoStandard,&info))
987 return MK_E_NOOBJECT;
989 *pFileTime=info.ftLastWriteTime;
992 return S_OK;
995 /******************************************************************************
996 * FileMoniker_Inverse
997 ******************************************************************************/
998 HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
1001 TRACE("(%p,%p)\n",iface,ppmk);
1003 return CreateAntiMoniker(ppmk);
1006 /******************************************************************************
1007 * FileMoniker_CommonPrefixWith
1008 ******************************************************************************/
1009 HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
1012 LPOLESTR pathThis,pathOther,*stringTable1,*stringTable2,commonPath;
1013 IBindCtx *pbind;
1014 DWORD mkSys;
1015 ULONG nb1,nb2,i,sameIdx;
1016 BOOL machimeNameCase=FALSE;
1018 if (ppmkPrefix==NULL)
1019 return E_POINTER;
1021 if (pmkOther==NULL)
1022 return E_INVALIDARG;
1024 *ppmkPrefix=0;
1026 /* check if we have the same type of moniker */
1027 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
1029 if(mkSys==MKSYS_FILEMONIKER){
1030 HRESULT ret;
1032 CreateBindCtx(0,&pbind);
1034 /* create a string based on common part of the two paths */
1036 IMoniker_GetDisplayName(iface,pbind,NULL,&pathThis);
1037 IMoniker_GetDisplayName(pmkOther,pbind,NULL,&pathOther);
1039 nb1=FileMonikerImpl_DecomposePath(pathThis,&stringTable1);
1040 nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2);
1042 if (nb1==0 || nb2==0)
1043 return MK_E_NOPREFIX;
1045 commonPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
1047 *commonPath=0;
1049 for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
1050 (stringTable2[sameIdx]!=NULL) &&
1051 (lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
1053 if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
1055 machimeNameCase=TRUE;
1057 for(i=2;i<sameIdx;i++)
1059 if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
1060 machimeNameCase=FALSE;
1061 break;
1065 if (machimeNameCase && *stringTable1[sameIdx-1]=='\\')
1066 sameIdx--;
1068 if (machimeNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
1069 ret = MK_E_NOPREFIX;
1070 else
1072 for(i=0;i<sameIdx;i++)
1073 strcatW(commonPath,stringTable1[i]);
1075 for(i=0;i<nb1;i++)
1076 CoTaskMemFree(stringTable1[i]);
1078 CoTaskMemFree(stringTable1);
1080 for(i=0;i<nb2;i++)
1081 CoTaskMemFree(stringTable2[i]);
1083 CoTaskMemFree(stringTable2);
1085 ret = CreateFileMoniker(commonPath,ppmkPrefix);
1087 HeapFree(GetProcessHeap(),0,commonPath);
1088 return ret;
1090 else
1091 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
1094 /******************************************************************************
1095 * DecomposePath (local function)
1096 ******************************************************************************/
1097 int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable)
1099 static const WCHAR bSlash[] = {'\\',0};
1100 WCHAR word[MAX_PATH];
1101 int i=0,j,tabIndex=0;
1102 LPOLESTR *strgtable ;
1104 int len=lstrlenW(str);
1106 TRACE("%s, %p\n", debugstr_w(str), *stringTable);
1108 strgtable =CoTaskMemAlloc(len*sizeof(LPOLESTR));
1110 if (strgtable==NULL)
1111 return E_OUTOFMEMORY;
1113 while(str[i]!=0){
1115 if(str[i]==bSlash[0]){
1117 strgtable[tabIndex]=CoTaskMemAlloc(2*sizeof(WCHAR));
1119 if (strgtable[tabIndex]==NULL)
1120 return E_OUTOFMEMORY;
1122 strcpyW(strgtable[tabIndex++],bSlash);
1124 i++;
1127 else {
1129 for(j=0; str[i]!=0 && str[i]!=bSlash[0] ; i++,j++)
1130 word[j]=str[i];
1132 word[j]=0;
1134 strgtable[tabIndex]=CoTaskMemAlloc(sizeof(WCHAR)*(j+1));
1136 if (strgtable[tabIndex]==NULL)
1137 return E_OUTOFMEMORY;
1139 strcpyW(strgtable[tabIndex++],word);
1142 strgtable[tabIndex]=NULL;
1144 *stringTable=strgtable;
1146 return tabIndex;
1149 /******************************************************************************
1150 * FileMoniker_RelativePathTo
1151 ******************************************************************************/
1152 HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
1154 IBindCtx *bind;
1155 HRESULT res;
1156 LPOLESTR str1=0,str2=0,*tabStr1=0,*tabStr2=0,relPath=0;
1157 DWORD len1=0,len2=0,sameIdx=0,j=0;
1158 static const WCHAR back[] ={'.','.','\\',0};
1160 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
1162 if (ppmkRelPath==NULL)
1163 return E_POINTER;
1165 if (pmOther==NULL)
1166 return E_INVALIDARG;
1168 res=CreateBindCtx(0,&bind);
1169 if (FAILED(res))
1170 return res;
1172 res=IMoniker_GetDisplayName(iface,bind,NULL,&str1);
1173 if (FAILED(res))
1174 return res;
1175 res=IMoniker_GetDisplayName(pmOther,bind,NULL,&str2);
1176 if (FAILED(res))
1177 return res;
1179 len1=FileMonikerImpl_DecomposePath(str1,&tabStr1);
1180 len2=FileMonikerImpl_DecomposePath(str2,&tabStr2);
1182 if (FAILED(len1) || FAILED(len2))
1183 return E_OUTOFMEMORY;
1185 /* count the number of similar items from the begin of the two paths */
1186 for(sameIdx=0; ( (tabStr1[sameIdx]!=NULL) &&
1187 (tabStr2[sameIdx]!=NULL) &&
1188 (lstrcmpiW(tabStr1[sameIdx],tabStr2[sameIdx])==0)); sameIdx++);
1190 /* begin the construction of relativePath */
1191 /* if the two paths have a consecutive similar item from the begin ! the relativePath will be composed */
1192 /* by "..\\" in the begin */
1193 relPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(1+lstrlenW(str1)+lstrlenW(str2)));
1195 *relPath=0;
1197 if (len2>0 && !(len1==1 && len2==1 && sameIdx==0))
1198 for(j=sameIdx;(tabStr1[j] != NULL); j++)
1199 if (*tabStr1[j]!='\\')
1200 strcatW(relPath,back);
1202 /* add items of the second path (similar items with the first path are not included) to the relativePath */
1203 for(j=sameIdx;tabStr2[j]!=NULL;j++)
1204 strcatW(relPath,tabStr2[j]);
1206 res=CreateFileMoniker(relPath,ppmkRelPath);
1208 for(j=0; tabStr1[j]!=NULL;j++)
1209 CoTaskMemFree(tabStr1[j]);
1210 for(j=0; tabStr2[j]!=NULL;j++)
1211 CoTaskMemFree(tabStr2[j]);
1212 CoTaskMemFree(tabStr1);
1213 CoTaskMemFree(tabStr2);
1214 CoTaskMemFree(str1);
1215 CoTaskMemFree(str2);
1216 HeapFree(GetProcessHeap(),0,relPath);
1218 if (len1==0 || len2==0 || (len1==1 && len2==1 && sameIdx==0))
1219 return MK_S_HIM;
1221 return res;
1224 /******************************************************************************
1225 * FileMoniker_GetDisplayName
1226 ******************************************************************************/
1227 HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,
1228 IBindCtx* pbc,
1229 IMoniker* pmkToLeft,
1230 LPOLESTR *ppszDisplayName)
1232 FileMonikerImpl *This = (FileMonikerImpl *)iface;
1234 int len=lstrlenW(This->filePathName);
1236 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
1238 if (ppszDisplayName==NULL)
1239 return E_POINTER;
1241 if (pmkToLeft!=NULL)
1242 return E_INVALIDARG;
1244 *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
1245 if (*ppszDisplayName==NULL)
1246 return E_OUTOFMEMORY;
1248 strcpyW(*ppszDisplayName,This->filePathName);
1250 return S_OK;
1253 /******************************************************************************
1254 * FileMoniker_ParseDisplayName
1255 ******************************************************************************/
1256 HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,
1257 IBindCtx* pbc,
1258 IMoniker* pmkToLeft,
1259 LPOLESTR pszDisplayName,
1260 ULONG* pchEaten,
1261 IMoniker** ppmkOut)
1263 FIXME("(%p,%p,%p,%p,%p,%p),stub!\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
1264 return E_NOTIMPL;
1267 /******************************************************************************
1268 * FileMoniker_IsSystemMoniker
1269 ******************************************************************************/
1270 HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
1272 TRACE("(%p,%p)\n",iface,pwdMksys);
1274 if (!pwdMksys)
1275 return E_POINTER;
1277 (*pwdMksys)=MKSYS_FILEMONIKER;
1279 return S_OK;
1282 /*******************************************************************************
1283 * FileMonikerIROTData_QueryInterface
1284 *******************************************************************************/
1285 HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
1288 ICOM_THIS_From_IROTData(IMoniker, iface);
1290 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
1292 return FileMonikerImpl_QueryInterface(This, riid, ppvObject);
1295 /***********************************************************************
1296 * FileMonikerIROTData_AddRef
1298 ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData *iface)
1300 ICOM_THIS_From_IROTData(IMoniker, iface);
1302 TRACE("(%p)\n",This);
1304 return FileMonikerImpl_AddRef(This);
1307 /***********************************************************************
1308 * FileMonikerIROTData_Release
1310 ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface)
1312 ICOM_THIS_From_IROTData(IMoniker, iface);
1314 TRACE("(%p)\n",This);
1316 return FileMonikerImpl_Release(This);
1319 /******************************************************************************
1320 * FileMonikerIROTData_GetComparaisonData
1321 ******************************************************************************/
1322 HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
1323 BYTE* pbData,
1324 ULONG cbMax,
1325 ULONG* pcbData)
1327 FIXME("(),stub!\n");
1328 return E_NOTIMPL;
1331 /******************************************************************************
1332 * CreateFileMoniker (OLE32.@)
1333 ******************************************************************************/
1334 HRESULT WINAPI CreateFileMoniker(LPCOLESTR lpszPathName, LPMONIKER * ppmk)
1336 FileMonikerImpl* newFileMoniker = 0;
1337 HRESULT hr = E_FAIL;
1338 IID riid=IID_IMoniker;
1340 TRACE("(%p,%p)\n",lpszPathName,ppmk);
1342 if (ppmk==NULL)
1343 return E_POINTER;
1345 if(lpszPathName==NULL)
1346 return MK_E_SYNTAX;
1348 *ppmk=0;
1350 newFileMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(FileMonikerImpl));
1352 if (newFileMoniker == 0)
1353 return E_OUTOFMEMORY;
1355 hr = FileMonikerImpl_Construct(newFileMoniker,lpszPathName);
1357 if (SUCCEEDED(hr))
1358 hr = FileMonikerImpl_QueryInterface((IMoniker*)newFileMoniker,&riid,(void**)ppmk);
1359 else
1360 HeapFree(GetProcessHeap(),0,newFileMoniker);
1362 return hr;