Implemented GetWindowTask16 on top of GetWindowThreadProcessId.
[wine/multimedia.git] / dlls / ole32 / filemoniker.c
blobbf70e784b687c83016c347105825efdce4f73bef
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 <string.h>
23 #include "winbase.h"
24 #include "winerror.h"
25 #include "winnls.h"
26 #include "wine/unicode.h"
27 #include "wine/debug.h"
28 #include "objbase.h"
29 #include "wine/obj_storage.h"
30 #include "wine/obj_moniker.h"
31 #include "wine/obj_base.h"
33 #include "compobj_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(ole);
37 /* filemoniker data structure */
38 typedef struct FileMonikerImpl{
40 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
42 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
43 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
45 ICOM_VTABLE(IROTData)* lpvtbl2; /* VTable relative to the IROTData interface.*/
47 ULONG ref; /* reference counter for this object */
49 LPOLESTR filePathName; /* path string identified by this filemoniker */
51 } FileMonikerImpl;
53 /********************************************************************************/
54 /* FileMoniker prototype functions : */
56 /* IUnknown prototype functions */
57 static HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
58 static ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface);
59 static ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface);
61 /* IPersist prototype functions */
62 static HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
64 /* IPersistStream prototype functions */
65 static HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface);
66 static HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface, IStream* pStm);
67 static HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
68 static HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
70 /* IMoniker prototype functions */
71 static HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
72 static HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
73 static HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
74 static HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
75 static HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
76 static HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
77 static HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
78 static HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
79 static HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime);
80 static HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
81 static HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
82 static HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
83 static HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
84 static HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
85 static HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
87 /********************************************************************************/
88 /* IROTData prototype functions */
90 /* IUnknown prototype functions */
91 static HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
92 static ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData* iface);
93 static ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface);
95 /* IROTData prototype function */
96 static HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
98 /* Local function used by filemoniker implementation */
99 HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* iface, LPCOLESTR lpszPathName);
100 HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* iface);
101 int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** tabStr);
104 /********************************************************************************/
105 /* Virtual function table for the FileMonikerImpl class which include IPersist,*/
106 /* IPersistStream and IMoniker functions. */
107 static ICOM_VTABLE(IMoniker) VT_FileMonikerImpl =
109 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
110 FileMonikerImpl_QueryInterface,
111 FileMonikerImpl_AddRef,
112 FileMonikerImpl_Release,
113 FileMonikerImpl_GetClassID,
114 FileMonikerImpl_IsDirty,
115 FileMonikerImpl_Load,
116 FileMonikerImpl_Save,
117 FileMonikerImpl_GetSizeMax,
118 FileMonikerImpl_BindToObject,
119 FileMonikerImpl_BindToStorage,
120 FileMonikerImpl_Reduce,
121 FileMonikerImpl_ComposeWith,
122 FileMonikerImpl_Enum,
123 FileMonikerImpl_IsEqual,
124 FileMonikerImpl_Hash,
125 FileMonikerImpl_IsRunning,
126 FileMonikerImpl_GetTimeOfLastChange,
127 FileMonikerImpl_Inverse,
128 FileMonikerImpl_CommonPrefixWith,
129 FileMonikerImpl_RelativePathTo,
130 FileMonikerImpl_GetDisplayName,
131 FileMonikerImpl_ParseDisplayName,
132 FileMonikerImpl_IsSystemMoniker
135 /********************************************************************************/
136 /* Virtual function table for the IROTData class. */
137 static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
139 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
140 FileMonikerROTDataImpl_QueryInterface,
141 FileMonikerROTDataImpl_AddRef,
142 FileMonikerROTDataImpl_Release,
143 FileMonikerROTDataImpl_GetComparaisonData
146 /*******************************************************************************
147 * FileMoniker_QueryInterface
148 *******************************************************************************/
149 HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
151 ICOM_THIS(FileMonikerImpl,iface);
153 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
155 /* Perform a sanity check on the parameters.*/
156 if ( (This==0) || (ppvObject==0) )
157 return E_INVALIDARG;
159 /* Initialize the return parameter */
160 *ppvObject = 0;
162 /* Compare the riid with the interface IDs implemented by this object.*/
163 if (IsEqualIID(&IID_IUnknown, riid) ||
164 IsEqualIID(&IID_IPersist, riid) ||
165 IsEqualIID(&IID_IPersistStream,riid) ||
166 IsEqualIID(&IID_IMoniker, riid)
168 *ppvObject = iface;
170 else if (IsEqualIID(&IID_IROTData, riid))
171 *ppvObject = (IROTData*)&(This->lpvtbl2);
173 /* Check that we obtained an interface.*/
174 if ((*ppvObject)==0)
175 return E_NOINTERFACE;
177 /* Query Interface always increases the reference count by one when it is successful */
178 FileMonikerImpl_AddRef(iface);
180 return S_OK;
183 /******************************************************************************
184 * FileMoniker_AddRef
185 ******************************************************************************/
186 ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface)
188 ICOM_THIS(FileMonikerImpl,iface);
190 TRACE("(%p)\n",iface);
192 return ++(This->ref);
195 /******************************************************************************
196 * FileMoniker_Release
197 ******************************************************************************/
198 ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface)
200 ICOM_THIS(FileMonikerImpl,iface);
202 TRACE("(%p)\n",iface);
204 This->ref--;
206 /* destroy the object if there's no more reference on it */
207 if (This->ref==0){
209 FileMonikerImpl_Destroy(This);
211 return 0;
213 return This->ref;
216 /******************************************************************************
217 * FileMoniker_GetClassID
218 ******************************************************************************/
219 HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface,
220 CLSID *pClassID)/* Pointer to CLSID of object */
222 TRACE("(%p,%p),stub!\n",iface,pClassID);
224 if (pClassID==NULL)
225 return E_POINTER;
227 *pClassID = CLSID_FileMoniker;
229 return S_OK;
232 /******************************************************************************
233 * FileMoniker_IsDirty
234 ******************************************************************************/
235 HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface)
237 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
238 method in the OLE-provided moniker interfaces always return S_FALSE because
239 their internal state never changes. */
241 TRACE("(%p)\n",iface);
243 return S_FALSE;
246 /******************************************************************************
247 * FileMoniker_Load
248 ******************************************************************************/
249 HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface,IStream* pStm)
251 HRESULT res;
252 CHAR* filePathA;
253 WCHAR* filePathW;
254 ULONG bread;
255 WORD wbuffer;
256 DWORD dwbuffer,length,i,doubleLenHex,doubleLenDec;
258 ICOM_THIS(FileMonikerImpl,iface);
260 TRACE("(%p,%p)\n",iface,pStm);
262 /* this function locates and reads from the stream the filePath string written by FileMonikerImpl_Save */
264 /* first WORD is non significative */
265 res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
266 if (bread!=sizeof(WORD) || wbuffer!=0)
267 return E_FAIL;
269 /* read filePath string length (plus one) */
270 res=IStream_Read(pStm,&length,sizeof(DWORD),&bread);
271 if (bread != sizeof(DWORD))
272 return E_FAIL;
274 /* read filePath string */
275 filePathA=HeapAlloc(GetProcessHeap(),0,length);
276 res=IStream_Read(pStm,filePathA,length,&bread);
277 if (bread != length)
278 return E_FAIL;
280 /* read the first constant */
281 IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
282 if (bread != sizeof(DWORD) || dwbuffer != 0xDEADFFFF)
283 return E_FAIL;
285 length--;
287 for(i=0;i<10;i++){
288 res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
289 if (bread!=sizeof(WORD) || wbuffer!=0)
290 return E_FAIL;
293 if (length>8)
294 length=0;
296 doubleLenHex=doubleLenDec=2*length;
297 if (length > 5)
298 doubleLenDec+=6;
300 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
301 if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenDec)
302 return E_FAIL;
304 if (length==0)
305 return res;
307 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
308 if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenHex)
309 return E_FAIL;
311 res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
312 if (bread!=sizeof(WORD) || wbuffer!=0x3)
313 return E_FAIL;
315 filePathW=HeapAlloc(GetProcessHeap(),0,(length+1)*sizeof(WCHAR));
316 filePathW[length]=0;
317 res=IStream_Read(pStm,filePathW,doubleLenHex,&bread);
318 if (bread!=doubleLenHex)
319 return E_FAIL;
321 if (This->filePathName!=NULL)
322 HeapFree(GetProcessHeap(),0,This->filePathName);
324 This->filePathName=filePathW;
326 HeapFree(GetProcessHeap(),0,filePathA);
328 return res;
331 /******************************************************************************
332 * FileMoniker_Save
333 ******************************************************************************/
334 HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface,
335 IStream* pStm,/* pointer to the stream where the object is to be saved */
336 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
338 /* this function saves data of this object. In the beginning I thougth
339 * that I have just to write the filePath string on Stream. But, when I
340 * tested this function whith windows programs samples, I noticed that it
341 * was not the case. So I analysed data written by this function on
342 * Windows and what this did function exactly ! But I have no idea about
343 * its logic !
344 * I guessed data which must be written on stream is:
345 * 1) WORD constant:zero
346 * 2) length of the path string ("\0" included)
347 * 3) path string type A
348 * 4) DWORD constant : 0xDEADFFFF
349 * 5) ten WORD constant: zero
350 * 6) DWORD: double-length of the the path string type W ("\0" not
351 * included)
352 * 7) WORD constant: 0x3
353 * 8) filePath unicode string.
354 * if the length(filePath) > 8 or length(filePath) == 8 stop at step 5)
357 ICOM_THIS(FileMonikerImpl,iface);
359 HRESULT res;
360 LPOLESTR filePathW=This->filePathName;
361 CHAR* filePathA;
362 DWORD len;
364 DWORD constant1 = 0xDEADFFFF; /* these constants are detected after analysing the data structure written by */
365 WORD constant2 = 0x3; /* FileMoniker_Save function in a windows program system */
367 WORD zero=0;
368 DWORD doubleLenHex;
369 DWORD doubleLenDec;
370 int i=0;
372 TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty);
374 if (pStm==NULL)
375 return E_POINTER;
377 /* write a DWORD set to 0 : constant */
378 res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
380 /* write length of filePath string ( "\0" included )*/
381 len = WideCharToMultiByte( CP_ACP, 0, filePathW, -1, NULL, 0, NULL, NULL );
382 res=IStream_Write(pStm,&len,sizeof(DWORD),NULL);
384 /* write filePath string type A */
385 filePathA=HeapAlloc(GetProcessHeap(),0,len);
386 WideCharToMultiByte( CP_ACP, 0, filePathW, -1, filePathA, len, NULL, NULL );
387 res=IStream_Write(pStm,filePathA,len,NULL);
388 HeapFree(GetProcessHeap(),0,filePathA);
390 /* write a DWORD set to 0xDEADFFFF: constant */
391 res=IStream_Write(pStm,&constant1,sizeof(DWORD),NULL);
393 len--;
394 /* write 10 times a DWORD set to 0 : constants */
395 for(i=0;i<10;i++)
396 res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
398 if (len>8)
399 len=0;
401 doubleLenHex=doubleLenDec=2*len;
402 if (len > 5)
403 doubleLenDec+=6;
405 /* write double-length of the path string ( "\0" included )*/
406 res=IStream_Write(pStm,&doubleLenDec,sizeof(DWORD),NULL);
408 if (len==0)
409 return res;
411 /* write double-length (hexa representation) of the path string ( "\0" included ) */
412 res=IStream_Write(pStm,&doubleLenHex,sizeof(DWORD),NULL);
414 /* write a WORD set to 0x3: constant */
415 res=IStream_Write(pStm,&constant2,sizeof(WORD),NULL);
417 /* write path unicode string */
418 res=IStream_Write(pStm,filePathW,doubleLenHex,NULL);
420 return res;
423 /******************************************************************************
424 * FileMoniker_GetSizeMax
425 ******************************************************************************/
426 HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface,
427 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
429 ICOM_THIS(FileMonikerImpl,iface);
430 DWORD len=lstrlenW(This->filePathName);
431 DWORD sizeMAx;
433 TRACE("(%p,%p)\n",iface,pcbSize);
435 if (pcbSize!=NULL)
436 return E_POINTER;
438 /* for more details see FileMonikerImpl_Save coments */
440 sizeMAx = sizeof(WORD) + /* first WORD is 0 */
441 sizeof(DWORD)+ /* length of filePath including "\0" in the end of the string */
442 (len+1)+ /* filePath string */
443 sizeof(DWORD)+ /* constant : 0xDEADFFFF */
444 10*sizeof(WORD)+ /* 10 zero WORD */
445 sizeof(DWORD); /* size of the unicode filePath: "\0" not included */
447 if (len==0 || len > 8)
448 return S_OK;
450 sizeMAx += sizeof(DWORD)+ /* size of the unicode filePath: "\0" not included */
451 sizeof(WORD)+ /* constant : 0x3 */
452 len*sizeof(WCHAR); /* unicde filePath string */
454 pcbSize->s.LowPart=sizeMAx;
455 pcbSize->s.HighPart=0;
457 return S_OK;
460 /******************************************************************************
461 * FileMoniker_Construct (local function)
462 *******************************************************************************/
463 HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* This, LPCOLESTR lpszPathName)
465 int nb=0,i;
466 int sizeStr=lstrlenW(lpszPathName);
467 LPOLESTR *tabStr=0;
468 WCHAR twoPoint[]={'.','.',0};
469 WCHAR bkSlash[]={'\\',0};
470 BYTE addBkSlash;
472 TRACE("(%p,%p)\n",This,lpszPathName);
474 /* Initialize the virtual fgunction table. */
475 This->lpvtbl1 = &VT_FileMonikerImpl;
476 This->lpvtbl2 = &VT_ROTDataImpl;
477 This->ref = 0;
479 This->filePathName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1));
481 if (This->filePathName==NULL)
482 return E_OUTOFMEMORY;
484 strcpyW(This->filePathName,lpszPathName);
486 nb=FileMonikerImpl_DecomposePath(This->filePathName,&tabStr);
488 if (nb > 0 ){
490 addBkSlash=1;
491 if (lstrcmpW(tabStr[0],twoPoint)!=0)
492 addBkSlash=0;
493 else
494 for(i=0;i<nb;i++){
496 if ( (lstrcmpW(tabStr[i],twoPoint)!=0) && (lstrcmpW(tabStr[i],bkSlash)!=0) ){
497 addBkSlash=0;
498 break;
500 else
502 if (lstrcmpW(tabStr[i],bkSlash)==0 && i<nb-1 && lstrcmpW(tabStr[i+1],bkSlash)==0){
503 *tabStr[i]=0;
504 sizeStr--;
505 addBkSlash=0;
506 break;
510 if (lstrcmpW(tabStr[nb-1],bkSlash)==0)
511 addBkSlash=0;
513 This->filePathName=HeapReAlloc(GetProcessHeap(),0,This->filePathName,(sizeStr+1)*sizeof(WCHAR));
515 *This->filePathName=0;
517 for(i=0;tabStr[i]!=NULL;i++)
518 strcatW(This->filePathName,tabStr[i]);
520 if (addBkSlash)
521 strcatW(This->filePathName,bkSlash);
524 for(i=0; tabStr[i]!=NULL;i++)
525 CoTaskMemFree(tabStr[i]);
526 CoTaskMemFree(tabStr);
528 return S_OK;
531 /******************************************************************************
532 * FileMoniker_Destroy (local function)
533 *******************************************************************************/
534 HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* This)
536 TRACE("(%p)\n",This);
538 if (This->filePathName!=NULL)
539 HeapFree(GetProcessHeap(),0,This->filePathName);
541 HeapFree(GetProcessHeap(),0,This);
543 return S_OK;
546 /******************************************************************************
547 * FileMoniker_BindToObject
548 ******************************************************************************/
549 HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,
550 IBindCtx* pbc,
551 IMoniker* pmkToLeft,
552 REFIID riid,
553 VOID** ppvResult)
555 HRESULT res=E_FAIL;
556 CLSID clsID;
557 IUnknown* pObj=0;
558 IRunningObjectTable *prot=0;
559 IPersistFile *ppf=0;
560 IClassFactory *pcf=0;
561 IClassActivator *pca=0;
563 ICOM_THIS(FileMonikerImpl,iface);
565 *ppvResult=0;
567 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
569 if(pmkToLeft==NULL){
571 res=IBindCtx_GetRunningObjectTable(pbc,&prot);
573 if (SUCCEEDED(res)){
574 /* if the requested class was loaded befor ! we dont need to reload it */
575 res = IRunningObjectTable_GetObject(prot,iface,&pObj);
577 if (res==S_FALSE){
578 /* first activation of this class */
579 res=GetClassFile(This->filePathName,&clsID);
580 if (SUCCEEDED(res)){
582 res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IPersistFile,(void**)&ppf);
583 if (SUCCEEDED(res)){
585 res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
586 if (SUCCEEDED(res)){
588 pObj=(IUnknown*)ppf;
589 IUnknown_AddRef(pObj);
596 else{
597 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassFactory,(void**)&pcf);
599 if (res==E_NOINTERFACE){
601 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassActivator,(void**)&pca);
603 if (res==E_NOINTERFACE)
604 return MK_E_INTERMEDIATEINTERFACENOTSUPPORTED;
606 if (pcf!=NULL){
608 IClassFactory_CreateInstance(pcf,NULL,&IID_IPersistFile,(void**)ppf);
610 res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
612 if (SUCCEEDED(res)){
614 pObj=(IUnknown*)ppf;
615 IUnknown_AddRef(pObj);
618 if (pca!=NULL){
620 FIXME("()\n");
622 /*res=GetClassFile(This->filePathName,&clsID);
624 if (SUCCEEDED(res)){
626 res=IClassActivator_GetClassObject(pca,&clsID,CLSCTX_ALL,0,&IID_IPersistFile,(void**)&ppf);
628 if (SUCCEEDED(res)){
630 pObj=(IUnknown*)ppf;
631 IUnknown_AddRef(pObj);
637 if (pObj!=NULL){
638 /* get the requested interface from the loaded class */
639 res= IUnknown_QueryInterface(pObj,riid,ppvResult);
641 IBindCtx_RegisterObjectBound(pbc,(IUnknown*)*ppvResult);
643 IUnknown_Release(pObj);
646 if (prot!=NULL)
647 IRunningObjectTable_Release(prot);
649 if (ppf!=NULL)
650 IPersistFile_Release(ppf);
652 if (pca!=NULL)
653 IClassActivator_Release(pca);
655 if (pcf!=NULL)
656 IClassFactory_Release(pcf);
658 return res;
661 /******************************************************************************
662 * FileMoniker_BindToStorage
663 ******************************************************************************/
664 HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,
665 IBindCtx* pbc,
666 IMoniker* pmkToLeft,
667 REFIID riid,
668 VOID** ppvObject)
670 LPOLESTR filePath=0;
671 IStorage *pstg=0;
672 HRESULT res;
674 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
676 if (pmkToLeft==NULL){
678 if (IsEqualIID(&IID_IStorage, riid)){
680 /* get the file name */
681 FileMonikerImpl_GetDisplayName(iface,pbc,pmkToLeft,&filePath);
683 /* verifie if the file contains a storage object */
684 res=StgIsStorageFile(filePath);
686 if(res==S_OK){
688 res=StgOpenStorage(filePath,NULL,STGM_READWRITE|STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
690 if (SUCCEEDED(res)){
692 *ppvObject=pstg;
694 IStorage_AddRef(pstg);
696 return res;
699 CoTaskMemFree(filePath);
701 else
702 if ( (IsEqualIID(&IID_IStream, riid)) || (IsEqualIID(&IID_ILockBytes, riid)) )
704 return E_UNSPEC;
705 else
707 return E_NOINTERFACE;
709 else {
711 FIXME("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
713 return E_NOTIMPL;
715 return res;
718 /******************************************************************************
719 * FileMoniker_Reduce
720 ******************************************************************************/
721 HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,
722 IBindCtx* pbc,
723 DWORD dwReduceHowFar,
724 IMoniker** ppmkToLeft,
725 IMoniker** ppmkReduced)
727 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
729 if (ppmkReduced==NULL)
730 return E_POINTER;
732 FileMonikerImpl_AddRef(iface);
734 *ppmkReduced=iface;
736 return MK_S_REDUCED_TO_SELF;
738 /******************************************************************************
739 * FileMoniker_ComposeWith
740 ******************************************************************************/
741 HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,
742 IMoniker* pmkRight,
743 BOOL fOnlyIfNotGeneric,
744 IMoniker** ppmkComposite)
746 HRESULT res;
747 LPOLESTR str1=0,str2=0,*strDec1=0,*strDec2=0,newStr=0;
748 WCHAR twoPoint[]={'.','.',0};
749 WCHAR bkSlash[]={'\\',0};
750 IBindCtx *bind=0;
751 int i=0,j=0,lastIdx1=0,lastIdx2=0;
752 DWORD mkSys;
754 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
756 if (ppmkComposite==NULL)
757 return E_POINTER;
759 if (pmkRight==NULL)
760 return E_INVALIDARG;
762 *ppmkComposite=0;
764 IMoniker_IsSystemMoniker(pmkRight,&mkSys);
766 /* check if we have two filemonikers to compose or not */
767 if(mkSys==MKSYS_FILEMONIKER){
769 CreateBindCtx(0,&bind);
771 FileMonikerImpl_GetDisplayName(iface,bind,NULL,&str1);
772 IMoniker_GetDisplayName(pmkRight,bind,NULL,&str2);
774 /* decompose pathnames of the two monikers : (to prepare the path merge operation ) */
775 lastIdx1=FileMonikerImpl_DecomposePath(str1,&strDec1)-1;
776 lastIdx2=FileMonikerImpl_DecomposePath(str2,&strDec2)-1;
778 if ((lastIdx1==-1 && lastIdx2>-1)||(lastIdx1==1 && lstrcmpW(strDec1[0],twoPoint)==0))
779 return MK_E_SYNTAX;
781 if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0)
782 lastIdx1--;
784 /* for etch "..\" in the left of str2 remove the right element from str1 */
785 for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ) ;i+=2){
787 lastIdx1-=2;
790 /* the length of the composed path string is raised by the sum of the two paths lengths */
791 newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
793 if (newStr==NULL)
794 return E_OUTOFMEMORY;
796 /* new path is the concatenation of the rest of str1 and str2 */
797 for(*newStr=0,j=0;j<=lastIdx1;j++)
798 strcatW(newStr,strDec1[j]);
800 if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
801 strcatW(newStr,bkSlash);
803 for(j=i;j<=lastIdx2;j++)
804 strcatW(newStr,strDec2[j]);
806 /* create a new moniker with the new string */
807 res=CreateFileMoniker(newStr,ppmkComposite);
809 /* free all strings space memory used by this function */
810 HeapFree(GetProcessHeap(),0,newStr);
812 for(i=0; strDec1[i]!=NULL;i++)
813 CoTaskMemFree(strDec1[i]);
814 for(i=0; strDec2[i]!=NULL;i++)
815 CoTaskMemFree(strDec2[i]);
816 CoTaskMemFree(strDec1);
817 CoTaskMemFree(strDec2);
819 CoTaskMemFree(str1);
820 CoTaskMemFree(str2);
822 return res;
824 else if(mkSys==MKSYS_ANTIMONIKER){
826 *ppmkComposite=NULL;
827 return S_OK;
829 else if (fOnlyIfNotGeneric){
831 *ppmkComposite=NULL;
832 return MK_E_NEEDGENERIC;
834 else
836 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
839 /******************************************************************************
840 * FileMoniker_Enum
841 ******************************************************************************/
842 HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
844 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
846 if (ppenumMoniker == NULL)
847 return E_POINTER;
849 *ppenumMoniker = NULL;
851 return S_OK;
854 /******************************************************************************
855 * FileMoniker_IsEqual
856 ******************************************************************************/
857 HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
859 ICOM_THIS(FileMonikerImpl,iface);
860 CLSID clsid;
861 LPOLESTR filePath;
862 IBindCtx* bind;
863 HRESULT res;
865 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
867 if (pmkOtherMoniker==NULL)
868 return S_FALSE;
870 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
872 if (!IsEqualCLSID(&clsid,&CLSID_FileMoniker))
873 return S_FALSE;
875 res = CreateBindCtx(0,&bind);
876 if (FAILED(res)) return res;
878 if (SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&filePath))) {
879 int result = lstrcmpiW(filePath, This->filePathName);
880 CoTaskMemFree(filePath);
881 if ( result == 0 ) return S_OK;
883 return S_FALSE;
887 /******************************************************************************
888 * FileMoniker_Hash
889 ******************************************************************************/
890 HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
892 ICOM_THIS(FileMonikerImpl,iface);
894 int h = 0,i,skip,len;
895 int off = 0;
896 LPOLESTR val;
898 if (pdwHash==NULL)
899 return E_POINTER;
901 val = This->filePathName;
902 len = lstrlenW(val);
904 if (len < 16) {
905 for (i = len ; i > 0; i--) {
906 h = (h * 37) + val[off++];
908 } else {
909 /* only sample some characters */
910 skip = len / 8;
911 for (i = len ; i > 0; i -= skip, off += skip) {
912 h = (h * 39) + val[off];
916 *pdwHash=h;
918 return S_OK;
921 /******************************************************************************
922 * FileMoniker_IsRunning
923 ******************************************************************************/
924 HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,
925 IBindCtx* pbc,
926 IMoniker* pmkToLeft,
927 IMoniker* pmkNewlyRunning)
929 IRunningObjectTable* rot;
930 HRESULT res;
932 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
934 if ( (pmkNewlyRunning!=NULL) && (IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK) )
935 return S_OK;
937 if (pbc==NULL)
938 return E_POINTER;
940 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
942 if (FAILED(res))
943 return res;
945 res = IRunningObjectTable_IsRunning(rot,iface);
947 IRunningObjectTable_Release(rot);
949 return res;
952 /******************************************************************************
953 * FileMoniker_GetTimeOfLastChange
954 ******************************************************************************/
955 HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
956 IBindCtx* pbc,
957 IMoniker* pmkToLeft,
958 FILETIME* pFileTime)
960 ICOM_THIS(FileMonikerImpl,iface);
961 IRunningObjectTable* rot;
962 HRESULT res;
963 WIN32_FILE_ATTRIBUTE_DATA info;
965 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pFileTime);
967 if (pFileTime==NULL)
968 return E_POINTER;
970 if (pmkToLeft!=NULL)
971 return E_INVALIDARG;
973 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
975 if (FAILED(res))
976 return res;
978 res= IRunningObjectTable_GetTimeOfLastChange(rot,iface,pFileTime);
980 if (FAILED(res)){ /* the moniker is not registred */
982 if (!GetFileAttributesExW(This->filePathName,GetFileExInfoStandard,&info))
983 return MK_E_NOOBJECT;
985 *pFileTime=info.ftLastWriteTime;
988 return S_OK;
991 /******************************************************************************
992 * FileMoniker_Inverse
993 ******************************************************************************/
994 HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
997 TRACE("(%p,%p)\n",iface,ppmk);
999 return CreateAntiMoniker(ppmk);
1002 /******************************************************************************
1003 * FileMoniker_CommonPrefixWith
1004 ******************************************************************************/
1005 HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
1008 LPOLESTR pathThis,pathOther,*stringTable1,*stringTable2,commonPath;
1009 IBindCtx *pbind;
1010 DWORD mkSys;
1011 ULONG nb1,nb2,i,sameIdx;
1012 BOOL machimeNameCase=FALSE;
1014 if (ppmkPrefix==NULL)
1015 return E_POINTER;
1017 if (pmkOther==NULL)
1018 return E_INVALIDARG;
1020 *ppmkPrefix=0;
1022 /* check if we have the same type of moniker */
1023 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
1025 if(mkSys==MKSYS_FILEMONIKER){
1027 CreateBindCtx(0,&pbind);
1029 /* create a string based on common part of the two paths */
1031 IMoniker_GetDisplayName(iface,pbind,NULL,&pathThis);
1032 IMoniker_GetDisplayName(pmkOther,pbind,NULL,&pathOther);
1034 nb1=FileMonikerImpl_DecomposePath(pathThis,&stringTable1);
1035 nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2);
1037 if (nb1==0 || nb2==0)
1038 return MK_E_NOPREFIX;
1040 commonPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
1042 *commonPath=0;
1044 for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
1045 (stringTable2[sameIdx]!=NULL) &&
1046 (lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
1048 if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
1050 machimeNameCase=TRUE;
1052 for(i=2;i<sameIdx;i++)
1054 if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
1055 machimeNameCase=FALSE;
1056 break;
1060 if (machimeNameCase && *stringTable1[sameIdx-1]=='\\')
1061 sameIdx--;
1063 if (machimeNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
1064 return MK_E_NOPREFIX;
1066 for(i=0;i<sameIdx;i++)
1067 strcatW(commonPath,stringTable1[i]);
1069 for(i=0;i<nb1;i++)
1070 CoTaskMemFree(stringTable1[i]);
1072 CoTaskMemFree(stringTable1);
1074 for(i=0;i<nb2;i++)
1075 CoTaskMemFree(stringTable2[i]);
1077 CoTaskMemFree(stringTable2);
1079 HeapFree(GetProcessHeap(),0,commonPath);
1081 return CreateFileMoniker(commonPath,ppmkPrefix);
1083 else
1084 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
1087 /******************************************************************************
1088 * DecomposePath (local function)
1089 ******************************************************************************/
1090 int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable)
1092 WCHAR bSlash[] = {'\\',0};
1093 WCHAR word[MAX_PATH];
1094 int i=0,j,tabIndex=0;
1095 LPOLESTR *strgtable ;
1097 int len=lstrlenW(str);
1099 TRACE("%s, %p\n", debugstr_w(str), *stringTable);
1101 strgtable =CoTaskMemAlloc(len*sizeof(LPOLESTR));
1103 if (strgtable==NULL)
1104 return E_OUTOFMEMORY;
1106 while(str[i]!=0){
1108 if(str[i]==bSlash[0]){
1110 strgtable[tabIndex]=CoTaskMemAlloc(2*sizeof(WCHAR));
1112 if (strgtable[tabIndex]==NULL)
1113 return E_OUTOFMEMORY;
1115 strcpyW(strgtable[tabIndex++],bSlash);
1117 i++;
1120 else {
1122 for(j=0; str[i]!=0 && str[i]!=bSlash[0] ; i++,j++)
1123 word[j]=str[i];
1125 word[j]=0;
1127 strgtable[tabIndex]=CoTaskMemAlloc(sizeof(WCHAR)*(j+1));
1129 if (strgtable[tabIndex]==NULL)
1130 return E_OUTOFMEMORY;
1132 strcpyW(strgtable[tabIndex++],word);
1135 strgtable[tabIndex]=NULL;
1137 *stringTable=strgtable;
1139 return tabIndex;
1142 /******************************************************************************
1143 * FileMoniker_RelativePathTo
1144 ******************************************************************************/
1145 HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
1147 IBindCtx *bind;
1148 HRESULT res;
1149 LPOLESTR str1=0,str2=0,*tabStr1=0,*tabStr2=0,relPath=0;
1150 DWORD len1=0,len2=0,sameIdx=0,j=0;
1151 WCHAR back[] ={'.','.','\\',0};
1153 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
1155 if (ppmkRelPath==NULL)
1156 return E_POINTER;
1158 if (pmOther==NULL)
1159 return E_INVALIDARG;
1161 res=CreateBindCtx(0,&bind);
1162 if (FAILED(res))
1163 return res;
1165 res=IMoniker_GetDisplayName(iface,bind,NULL,&str1);
1166 if (FAILED(res))
1167 return res;
1168 res=IMoniker_GetDisplayName(pmOther,bind,NULL,&str2);
1169 if (FAILED(res))
1170 return res;
1172 len1=FileMonikerImpl_DecomposePath(str1,&tabStr1);
1173 len2=FileMonikerImpl_DecomposePath(str2,&tabStr2);
1175 if (FAILED(len1) || FAILED(len2))
1176 return E_OUTOFMEMORY;
1178 /* count the number of similar items from the begin of the two paths */
1179 for(sameIdx=0; ( (tabStr1[sameIdx]!=NULL) &&
1180 (tabStr2[sameIdx]!=NULL) &&
1181 (lstrcmpiW(tabStr1[sameIdx],tabStr2[sameIdx])==0)); sameIdx++);
1183 /* begin the construction of relativePath */
1184 /* if the two paths have a consecutive similar item from the begin ! the relativePath will be composed */
1185 /* by "..\\" in the begin */
1186 relPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(1+lstrlenW(str1)+lstrlenW(str2)));
1188 *relPath=0;
1190 if (len2>0 && !(len1==1 && len2==1 && sameIdx==0))
1191 for(j=sameIdx;(tabStr1[j] != NULL); j++)
1192 if (*tabStr1[j]!='\\')
1193 strcatW(relPath,back);
1195 /* add items of the second path (similar items with the first path are not included) to the relativePath */
1196 for(j=sameIdx;tabStr2[j]!=NULL;j++)
1197 strcatW(relPath,tabStr2[j]);
1199 res=CreateFileMoniker(relPath,ppmkRelPath);
1201 for(j=0; tabStr1[j]!=NULL;j++)
1202 CoTaskMemFree(tabStr1[j]);
1203 for(j=0; tabStr2[j]!=NULL;j++)
1204 CoTaskMemFree(tabStr2[j]);
1205 CoTaskMemFree(tabStr1);
1206 CoTaskMemFree(tabStr2);
1207 CoTaskMemFree(str1);
1208 CoTaskMemFree(str2);
1209 HeapFree(GetProcessHeap(),0,relPath);
1211 if (len1==0 || len2==0 || (len1==1 && len2==1 && sameIdx==0))
1212 return MK_S_HIM;
1214 return res;
1217 /******************************************************************************
1218 * FileMoniker_GetDisplayName
1219 ******************************************************************************/
1220 HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,
1221 IBindCtx* pbc,
1222 IMoniker* pmkToLeft,
1223 LPOLESTR *ppszDisplayName)
1225 ICOM_THIS(FileMonikerImpl,iface);
1227 int len=lstrlenW(This->filePathName);
1229 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
1231 if (ppszDisplayName==NULL)
1232 return E_POINTER;
1234 if (pmkToLeft!=NULL)
1235 return E_INVALIDARG;
1237 *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
1238 if (*ppszDisplayName==NULL)
1239 return E_OUTOFMEMORY;
1241 strcpyW(*ppszDisplayName,This->filePathName);
1243 return S_OK;
1246 /******************************************************************************
1247 * FileMoniker_ParseDisplayName
1248 ******************************************************************************/
1249 HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,
1250 IBindCtx* pbc,
1251 IMoniker* pmkToLeft,
1252 LPOLESTR pszDisplayName,
1253 ULONG* pchEaten,
1254 IMoniker** ppmkOut)
1256 FIXME("(%p,%p,%p,%p,%p,%p),stub!\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
1257 return E_NOTIMPL;
1260 /******************************************************************************
1261 * FileMoniker_IsSystemMoniker
1262 ******************************************************************************/
1263 HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
1265 TRACE("(%p,%p)\n",iface,pwdMksys);
1267 if (!pwdMksys)
1268 return E_POINTER;
1270 (*pwdMksys)=MKSYS_FILEMONIKER;
1272 return S_OK;
1275 /*******************************************************************************
1276 * FileMonikerIROTData_QueryInterface
1277 *******************************************************************************/
1278 HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
1281 ICOM_THIS_From_IROTData(IMoniker, iface);
1283 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
1285 return FileMonikerImpl_QueryInterface(This, riid, ppvObject);
1288 /***********************************************************************
1289 * FileMonikerIROTData_AddRef
1291 ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData *iface)
1293 ICOM_THIS_From_IROTData(IMoniker, iface);
1295 TRACE("(%p)\n",This);
1297 return FileMonikerImpl_AddRef(This);
1300 /***********************************************************************
1301 * FileMonikerIROTData_Release
1303 ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface)
1305 ICOM_THIS_From_IROTData(IMoniker, iface);
1307 TRACE("(%p)\n",This);
1309 return FileMonikerImpl_Release(This);
1312 /******************************************************************************
1313 * FileMonikerIROTData_GetComparaisonData
1314 ******************************************************************************/
1315 HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
1316 BYTE* pbData,
1317 ULONG cbMax,
1318 ULONG* pcbData)
1320 FIXME("(),stub!\n");
1321 return E_NOTIMPL;
1324 /******************************************************************************
1325 * CreateFileMoniker (OLE2.28)
1326 ******************************************************************************/
1327 HRESULT WINAPI CreateFileMoniker16(LPCOLESTR16 lpszPathName,LPMONIKER* ppmk)
1330 FIXME("(%s,%p),stub!\n",lpszPathName,ppmk);
1331 return E_NOTIMPL;
1334 /******************************************************************************
1335 * CreateFileMoniker (OLE32.55)
1336 ******************************************************************************/
1337 HRESULT WINAPI CreateFileMoniker(LPCOLESTR lpszPathName, LPMONIKER * ppmk)
1339 FileMonikerImpl* newFileMoniker = 0;
1340 HRESULT hr = E_FAIL;
1341 IID riid=IID_IMoniker;
1343 TRACE("(%p,%p)\n",lpszPathName,ppmk);
1345 if (ppmk==NULL)
1346 return E_POINTER;
1348 if(lpszPathName==NULL)
1349 return MK_E_SYNTAX;
1351 *ppmk=0;
1353 newFileMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(FileMonikerImpl));
1355 if (newFileMoniker == 0)
1356 return E_OUTOFMEMORY;
1358 hr = FileMonikerImpl_Construct(newFileMoniker,lpszPathName);
1360 if (SUCCEEDED(hr))
1361 hr = FileMonikerImpl_QueryInterface((IMoniker*)newFileMoniker,&riid,(void**)ppmk);
1362 else
1363 HeapFree(GetProcessHeap(),0,newFileMoniker);
1365 return hr;