Assorted spelling fixes.
[wine/wine-gecko.git] / dlls / ole32 / filemoniker.c
blob60747597632a757915c403217496e54e8b3875bc
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 ICOM_VTABLE(IMoniker)* 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 ICOM_VTABLE(IROTData)* 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 ICOM_VTABLE(IMoniker) VT_FileMonikerImpl =
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
142 /********************************************************************************/
143 /* Virtual function table for the IROTData class. */
144 static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
146 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
147 FileMonikerROTDataImpl_QueryInterface,
148 FileMonikerROTDataImpl_AddRef,
149 FileMonikerROTDataImpl_Release,
150 FileMonikerROTDataImpl_GetComparaisonData
153 /*******************************************************************************
154 * FileMoniker_QueryInterface
155 *******************************************************************************/
156 HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
158 ICOM_THIS(FileMonikerImpl,iface);
160 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
162 /* Perform a sanity check on the parameters.*/
163 if ( (This==0) || (ppvObject==0) )
164 return E_INVALIDARG;
166 /* Initialize the return parameter */
167 *ppvObject = 0;
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)
175 *ppvObject = iface;
177 else if (IsEqualIID(&IID_IROTData, riid))
178 *ppvObject = (IROTData*)&(This->lpvtbl2);
180 /* Check that we obtained an interface.*/
181 if ((*ppvObject)==0)
182 return E_NOINTERFACE;
184 /* Query Interface always increases the reference count by one when it is successful */
185 FileMonikerImpl_AddRef(iface);
187 return S_OK;
190 /******************************************************************************
191 * FileMoniker_AddRef
192 ******************************************************************************/
193 ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface)
195 ICOM_THIS(FileMonikerImpl,iface);
197 TRACE("(%p)\n",iface);
199 return ++(This->ref);
202 /******************************************************************************
203 * FileMoniker_Release
204 ******************************************************************************/
205 ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface)
207 ICOM_THIS(FileMonikerImpl,iface);
209 TRACE("(%p)\n",iface);
211 This->ref--;
213 /* destroy the object if there's no more reference on it */
214 if (This->ref==0){
216 FileMonikerImpl_Destroy(This);
218 return 0;
220 return This->ref;
223 /******************************************************************************
224 * FileMoniker_GetClassID
225 ******************************************************************************/
226 HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface,
227 CLSID *pClassID)/* Pointer to CLSID of object */
229 TRACE("(%p,%p),stub!\n",iface,pClassID);
231 if (pClassID==NULL)
232 return E_POINTER;
234 *pClassID = CLSID_FileMoniker;
236 return S_OK;
239 /******************************************************************************
240 * FileMoniker_IsDirty
241 ******************************************************************************/
242 HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface)
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. */
248 TRACE("(%p)\n",iface);
250 return S_FALSE;
253 /******************************************************************************
254 * FileMoniker_Load
255 ******************************************************************************/
256 HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface,IStream* pStm)
258 HRESULT res;
259 CHAR* filePathA;
260 WCHAR* filePathW;
261 ULONG bread;
262 WORD wbuffer;
263 DWORD dwbuffer,length,i,doubleLenHex,doubleLenDec;
265 ICOM_THIS(FileMonikerImpl,iface);
267 TRACE("(%p,%p)\n",iface,pStm);
269 /* this function locates and reads from the stream the filePath string written by FileMonikerImpl_Save */
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;
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;
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;
288 /* read the first constant */
289 IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
290 if (bread != sizeof(DWORD) || dwbuffer != 0xDEADFFFF)
291 return E_FAIL;
293 length--;
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;
301 if (length>8)
302 length=0;
304 doubleLenHex=doubleLenDec=2*length;
305 if (length > 5)
306 doubleLenDec+=6;
308 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
309 if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenDec)
310 return E_FAIL;
312 if (length==0)
313 return res;
315 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
316 if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenHex)
317 return E_FAIL;
319 res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
320 if (bread!=sizeof(WORD) || wbuffer!=0x3)
321 return E_FAIL;
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;
331 if (This->filePathName!=NULL)
332 HeapFree(GetProcessHeap(),0,This->filePathName);
334 This->filePathName=filePathW;
336 return res;
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 */
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)
365 ICOM_THIS(FileMonikerImpl,iface);
367 HRESULT res;
368 LPOLESTR filePathW=This->filePathName;
369 CHAR* filePathA;
370 DWORD len;
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 */
375 WORD zero=0;
376 DWORD doubleLenHex;
377 DWORD doubleLenDec;
378 int i=0;
380 TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty);
382 if (pStm==NULL)
383 return E_POINTER;
385 /* write a DWORD set to 0 : constant */
386 res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
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);
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);
398 /* write a DWORD set to 0xDEADFFFF: constant */
399 res=IStream_Write(pStm,&constant1,sizeof(DWORD),NULL);
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);
406 if (len>8)
407 len=0;
409 doubleLenHex=doubleLenDec=2*len;
410 if (len > 5)
411 doubleLenDec+=6;
413 /* write double-length of the path string ( "\0" included )*/
414 res=IStream_Write(pStm,&doubleLenDec,sizeof(DWORD),NULL);
416 if (len==0)
417 return res;
419 /* write double-length (hexa representation) of the path string ( "\0" included ) */
420 res=IStream_Write(pStm,&doubleLenHex,sizeof(DWORD),NULL);
422 /* write a WORD set to 0x3: constant */
423 res=IStream_Write(pStm,&constant2,sizeof(WORD),NULL);
425 /* write path unicode string */
426 res=IStream_Write(pStm,filePathW,doubleLenHex,NULL);
428 return res;
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 */
437 ICOM_THIS(FileMonikerImpl,iface);
438 DWORD len=lstrlenW(This->filePathName);
439 DWORD sizeMAx;
441 TRACE("(%p,%p)\n",iface,pcbSize);
443 if (pcbSize!=NULL)
444 return E_POINTER;
446 /* for more details see FileMonikerImpl_Save coments */
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 */
455 if (len==0 || len > 8)
456 return S_OK;
458 sizeMAx += sizeof(DWORD)+ /* size of the unicode filePath: "\0" not included */
459 sizeof(WORD)+ /* constant : 0x3 */
460 len*sizeof(WCHAR); /* unicde filePath string */
462 pcbSize->u.LowPart=sizeMAx;
463 pcbSize->u.HighPart=0;
465 return S_OK;
468 /******************************************************************************
469 * FileMoniker_Construct (local function)
470 *******************************************************************************/
471 HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* This, LPCOLESTR lpszPathName)
473 int nb=0,i;
474 int sizeStr=lstrlenW(lpszPathName);
475 LPOLESTR *tabStr=0;
476 static const WCHAR twoPoint[]={'.','.',0};
477 static const WCHAR bkSlash[]={'\\',0};
478 BYTE addBkSlash;
480 TRACE("(%p,%p)\n",This,lpszPathName);
482 /* Initialize the virtual fgunction table. */
483 This->lpvtbl1 = &VT_FileMonikerImpl;
484 This->lpvtbl2 = &VT_ROTDataImpl;
485 This->ref = 0;
487 This->filePathName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1));
489 if (This->filePathName==NULL)
490 return E_OUTOFMEMORY;
492 strcpyW(This->filePathName,lpszPathName);
494 nb=FileMonikerImpl_DecomposePath(This->filePathName,&tabStr);
496 if (nb > 0 ){
498 addBkSlash=1;
499 if (lstrcmpW(tabStr[0],twoPoint)!=0)
500 addBkSlash=0;
501 else
502 for(i=0;i<nb;i++){
504 if ( (lstrcmpW(tabStr[i],twoPoint)!=0) && (lstrcmpW(tabStr[i],bkSlash)!=0) ){
505 addBkSlash=0;
506 break;
508 else
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;
518 if (lstrcmpW(tabStr[nb-1],bkSlash)==0)
519 addBkSlash=0;
521 This->filePathName=HeapReAlloc(GetProcessHeap(),0,This->filePathName,(sizeStr+1)*sizeof(WCHAR));
523 *This->filePathName=0;
525 for(i=0;tabStr[i]!=NULL;i++)
526 strcatW(This->filePathName,tabStr[i]);
528 if (addBkSlash)
529 strcatW(This->filePathName,bkSlash);
532 for(i=0; tabStr[i]!=NULL;i++)
533 CoTaskMemFree(tabStr[i]);
534 CoTaskMemFree(tabStr);
536 return S_OK;
539 /******************************************************************************
540 * FileMoniker_Destroy (local function)
541 *******************************************************************************/
542 HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* This)
544 TRACE("(%p)\n",This);
546 if (This->filePathName!=NULL)
547 HeapFree(GetProcessHeap(),0,This->filePathName);
549 HeapFree(GetProcessHeap(),0,This);
551 return S_OK;
554 /******************************************************************************
555 * FileMoniker_BindToObject
556 ******************************************************************************/
557 HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,
558 IBindCtx* pbc,
559 IMoniker* pmkToLeft,
560 REFIID riid,
561 VOID** ppvResult)
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;
571 ICOM_THIS(FileMonikerImpl,iface);
573 *ppvResult=0;
575 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
577 if(pmkToLeft==NULL){
579 res=IBindCtx_GetRunningObjectTable(pbc,&prot);
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);
585 if (res==S_FALSE){
586 /* first activation of this class */
587 res=GetClassFile(This->filePathName,&clsID);
588 if (SUCCEEDED(res)){
590 res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IPersistFile,(void**)&ppf);
591 if (SUCCEEDED(res)){
593 res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
594 if (SUCCEEDED(res)){
596 pObj=(IUnknown*)ppf;
597 IUnknown_AddRef(pObj);
604 else{
605 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassFactory,(void**)&pcf);
607 if (res==E_NOINTERFACE){
609 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassActivator,(void**)&pca);
611 if (res==E_NOINTERFACE)
612 return MK_E_INTERMEDIATEINTERFACENOTSUPPORTED;
614 if (pcf!=NULL){
616 IClassFactory_CreateInstance(pcf,NULL,&IID_IPersistFile,(void**)ppf);
618 res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
620 if (SUCCEEDED(res)){
622 pObj=(IUnknown*)ppf;
623 IUnknown_AddRef(pObj);
626 if (pca!=NULL){
628 FIXME("()\n");
630 /*res=GetClassFile(This->filePathName,&clsID);
632 if (SUCCEEDED(res)){
634 res=IClassActivator_GetClassObject(pca,&clsID,CLSCTX_ALL,0,&IID_IPersistFile,(void**)&ppf);
636 if (SUCCEEDED(res)){
638 pObj=(IUnknown*)ppf;
639 IUnknown_AddRef(pObj);
645 if (pObj!=NULL){
646 /* get the requested interface from the loaded class */
647 res= IUnknown_QueryInterface(pObj,riid,ppvResult);
649 IBindCtx_RegisterObjectBound(pbc,(IUnknown*)*ppvResult);
651 IUnknown_Release(pObj);
654 if (prot!=NULL)
655 IRunningObjectTable_Release(prot);
657 if (ppf!=NULL)
658 IPersistFile_Release(ppf);
660 if (pca!=NULL)
661 IClassActivator_Release(pca);
663 if (pcf!=NULL)
664 IClassFactory_Release(pcf);
666 return res;
669 /******************************************************************************
670 * FileMoniker_BindToStorage
671 ******************************************************************************/
672 HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,
673 IBindCtx* pbc,
674 IMoniker* pmkToLeft,
675 REFIID riid,
676 VOID** ppvObject)
678 LPOLESTR filePath=0;
679 IStorage *pstg=0;
680 HRESULT res;
682 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
684 if (pmkToLeft==NULL){
686 if (IsEqualIID(&IID_IStorage, riid)){
688 /* get the file name */
689 FileMonikerImpl_GetDisplayName(iface,pbc,pmkToLeft,&filePath);
691 /* verifie if the file contains a storage object */
692 res=StgIsStorageFile(filePath);
694 if(res==S_OK){
696 res=StgOpenStorage(filePath,NULL,STGM_READWRITE|STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
698 if (SUCCEEDED(res)){
700 *ppvObject=pstg;
702 IStorage_AddRef(pstg);
704 return res;
707 CoTaskMemFree(filePath);
709 else
710 if ( (IsEqualIID(&IID_IStream, riid)) || (IsEqualIID(&IID_ILockBytes, riid)) )
711 return E_FAIL;
712 else
713 return E_NOINTERFACE;
715 else {
717 FIXME("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
719 return E_NOTIMPL;
721 return res;
724 /******************************************************************************
725 * FileMoniker_Reduce
726 ******************************************************************************/
727 HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,
728 IBindCtx* pbc,
729 DWORD dwReduceHowFar,
730 IMoniker** ppmkToLeft,
731 IMoniker** ppmkReduced)
733 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
735 if (ppmkReduced==NULL)
736 return E_POINTER;
738 FileMonikerImpl_AddRef(iface);
740 *ppmkReduced=iface;
742 return MK_S_REDUCED_TO_SELF;
744 /******************************************************************************
745 * FileMoniker_ComposeWith
746 ******************************************************************************/
747 HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,
748 IMoniker* pmkRight,
749 BOOL fOnlyIfNotGeneric,
750 IMoniker** ppmkComposite)
752 HRESULT res;
753 LPOLESTR str1=0,str2=0,*strDec1=0,*strDec2=0,newStr=0;
754 static const WCHAR twoPoint[]={'.','.',0};
755 static const WCHAR bkSlash[]={'\\',0};
756 IBindCtx *bind=0;
757 int i=0,j=0,lastIdx1=0,lastIdx2=0;
758 DWORD mkSys;
760 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
762 if (ppmkComposite==NULL)
763 return E_POINTER;
765 if (pmkRight==NULL)
766 return E_INVALIDARG;
768 *ppmkComposite=0;
770 IMoniker_IsSystemMoniker(pmkRight,&mkSys);
772 /* check if we have two filemonikers to compose or not */
773 if(mkSys==MKSYS_FILEMONIKER){
775 CreateBindCtx(0,&bind);
777 FileMonikerImpl_GetDisplayName(iface,bind,NULL,&str1);
778 IMoniker_GetDisplayName(pmkRight,bind,NULL,&str2);
780 /* decompose pathnames of the two monikers : (to prepare the path merge operation ) */
781 lastIdx1=FileMonikerImpl_DecomposePath(str1,&strDec1)-1;
782 lastIdx2=FileMonikerImpl_DecomposePath(str2,&strDec2)-1;
784 if ((lastIdx1==-1 && lastIdx2>-1)||(lastIdx1==1 && lstrcmpW(strDec1[0],twoPoint)==0))
785 return MK_E_SYNTAX;
787 if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0)
788 lastIdx1--;
790 /* for etch "..\" in the left of str2 remove the right element from str1 */
791 for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ) ;i+=2){
793 lastIdx1-=2;
796 /* the length of the composed path string is raised by the sum of the two paths lengths */
797 newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
799 if (newStr==NULL)
800 return E_OUTOFMEMORY;
802 /* new path is the concatenation of the rest of str1 and str2 */
803 for(*newStr=0,j=0;j<=lastIdx1;j++)
804 strcatW(newStr,strDec1[j]);
806 if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
807 strcatW(newStr,bkSlash);
809 for(j=i;j<=lastIdx2;j++)
810 strcatW(newStr,strDec2[j]);
812 /* create a new moniker with the new string */
813 res=CreateFileMoniker(newStr,ppmkComposite);
815 /* free all strings space memory used by this function */
816 HeapFree(GetProcessHeap(),0,newStr);
818 for(i=0; strDec1[i]!=NULL;i++)
819 CoTaskMemFree(strDec1[i]);
820 for(i=0; strDec2[i]!=NULL;i++)
821 CoTaskMemFree(strDec2[i]);
822 CoTaskMemFree(strDec1);
823 CoTaskMemFree(strDec2);
825 CoTaskMemFree(str1);
826 CoTaskMemFree(str2);
828 return res;
830 else if(mkSys==MKSYS_ANTIMONIKER){
832 *ppmkComposite=NULL;
833 return S_OK;
835 else if (fOnlyIfNotGeneric){
837 *ppmkComposite=NULL;
838 return MK_E_NEEDGENERIC;
840 else
842 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
845 /******************************************************************************
846 * FileMoniker_Enum
847 ******************************************************************************/
848 HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
850 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
852 if (ppenumMoniker == NULL)
853 return E_POINTER;
855 *ppenumMoniker = NULL;
857 return S_OK;
860 /******************************************************************************
861 * FileMoniker_IsEqual
862 ******************************************************************************/
863 HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
865 ICOM_THIS(FileMonikerImpl,iface);
866 CLSID clsid;
867 LPOLESTR filePath;
868 IBindCtx* bind;
869 HRESULT res;
871 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
873 if (pmkOtherMoniker==NULL)
874 return S_FALSE;
876 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
878 if (!IsEqualCLSID(&clsid,&CLSID_FileMoniker))
879 return S_FALSE;
881 res = CreateBindCtx(0,&bind);
882 if (FAILED(res)) return res;
884 if (SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&filePath))) {
885 int result = lstrcmpiW(filePath, This->filePathName);
886 CoTaskMemFree(filePath);
887 if ( result == 0 ) return S_OK;
889 return S_FALSE;
893 /******************************************************************************
894 * FileMoniker_Hash
895 ******************************************************************************/
896 HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
898 ICOM_THIS(FileMonikerImpl,iface);
900 int h = 0,i,skip,len;
901 int off = 0;
902 LPOLESTR val;
904 if (pdwHash==NULL)
905 return E_POINTER;
907 val = This->filePathName;
908 len = lstrlenW(val);
910 if (len < 16) {
911 for (i = len ; i > 0; i--) {
912 h = (h * 37) + val[off++];
914 } else {
915 /* only sample some characters */
916 skip = len / 8;
917 for (i = len ; i > 0; i -= skip, off += skip) {
918 h = (h * 39) + val[off];
922 *pdwHash=h;
924 return S_OK;
927 /******************************************************************************
928 * FileMoniker_IsRunning
929 ******************************************************************************/
930 HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,
931 IBindCtx* pbc,
932 IMoniker* pmkToLeft,
933 IMoniker* pmkNewlyRunning)
935 IRunningObjectTable* rot;
936 HRESULT res;
938 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
940 if ( (pmkNewlyRunning!=NULL) && (IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK) )
941 return S_OK;
943 if (pbc==NULL)
944 return E_POINTER;
946 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
948 if (FAILED(res))
949 return res;
951 res = IRunningObjectTable_IsRunning(rot,iface);
953 IRunningObjectTable_Release(rot);
955 return res;
958 /******************************************************************************
959 * FileMoniker_GetTimeOfLastChange
960 ******************************************************************************/
961 HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
962 IBindCtx* pbc,
963 IMoniker* pmkToLeft,
964 FILETIME* pFileTime)
966 ICOM_THIS(FileMonikerImpl,iface);
967 IRunningObjectTable* rot;
968 HRESULT res;
969 WIN32_FILE_ATTRIBUTE_DATA info;
971 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pFileTime);
973 if (pFileTime==NULL)
974 return E_POINTER;
976 if (pmkToLeft!=NULL)
977 return E_INVALIDARG;
979 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
981 if (FAILED(res))
982 return res;
984 res= IRunningObjectTable_GetTimeOfLastChange(rot,iface,pFileTime);
986 if (FAILED(res)){ /* the moniker is not registered */
988 if (!GetFileAttributesExW(This->filePathName,GetFileExInfoStandard,&info))
989 return MK_E_NOOBJECT;
991 *pFileTime=info.ftLastWriteTime;
994 return S_OK;
997 /******************************************************************************
998 * FileMoniker_Inverse
999 ******************************************************************************/
1000 HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
1003 TRACE("(%p,%p)\n",iface,ppmk);
1005 return CreateAntiMoniker(ppmk);
1008 /******************************************************************************
1009 * FileMoniker_CommonPrefixWith
1010 ******************************************************************************/
1011 HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
1014 LPOLESTR pathThis,pathOther,*stringTable1,*stringTable2,commonPath;
1015 IBindCtx *pbind;
1016 DWORD mkSys;
1017 ULONG nb1,nb2,i,sameIdx;
1018 BOOL machimeNameCase=FALSE;
1020 if (ppmkPrefix==NULL)
1021 return E_POINTER;
1023 if (pmkOther==NULL)
1024 return E_INVALIDARG;
1026 *ppmkPrefix=0;
1028 /* check if we have the same type of moniker */
1029 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
1031 if(mkSys==MKSYS_FILEMONIKER){
1032 HRESULT ret;
1034 CreateBindCtx(0,&pbind);
1036 /* create a string based on common part of the two paths */
1038 IMoniker_GetDisplayName(iface,pbind,NULL,&pathThis);
1039 IMoniker_GetDisplayName(pmkOther,pbind,NULL,&pathOther);
1041 nb1=FileMonikerImpl_DecomposePath(pathThis,&stringTable1);
1042 nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2);
1044 if (nb1==0 || nb2==0)
1045 return MK_E_NOPREFIX;
1047 commonPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
1049 *commonPath=0;
1051 for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
1052 (stringTable2[sameIdx]!=NULL) &&
1053 (lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
1055 if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
1057 machimeNameCase=TRUE;
1059 for(i=2;i<sameIdx;i++)
1061 if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
1062 machimeNameCase=FALSE;
1063 break;
1067 if (machimeNameCase && *stringTable1[sameIdx-1]=='\\')
1068 sameIdx--;
1070 if (machimeNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
1071 ret = MK_E_NOPREFIX;
1072 else
1074 for(i=0;i<sameIdx;i++)
1075 strcatW(commonPath,stringTable1[i]);
1077 for(i=0;i<nb1;i++)
1078 CoTaskMemFree(stringTable1[i]);
1080 CoTaskMemFree(stringTable1);
1082 for(i=0;i<nb2;i++)
1083 CoTaskMemFree(stringTable2[i]);
1085 CoTaskMemFree(stringTable2);
1087 ret = CreateFileMoniker(commonPath,ppmkPrefix);
1089 HeapFree(GetProcessHeap(),0,commonPath);
1090 return ret;
1092 else
1093 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
1096 /******************************************************************************
1097 * DecomposePath (local function)
1098 ******************************************************************************/
1099 int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable)
1101 static const WCHAR bSlash[] = {'\\',0};
1102 WCHAR word[MAX_PATH];
1103 int i=0,j,tabIndex=0;
1104 LPOLESTR *strgtable ;
1106 int len=lstrlenW(str);
1108 TRACE("%s, %p\n", debugstr_w(str), *stringTable);
1110 strgtable =CoTaskMemAlloc(len*sizeof(LPOLESTR));
1112 if (strgtable==NULL)
1113 return E_OUTOFMEMORY;
1115 while(str[i]!=0){
1117 if(str[i]==bSlash[0]){
1119 strgtable[tabIndex]=CoTaskMemAlloc(2*sizeof(WCHAR));
1121 if (strgtable[tabIndex]==NULL)
1122 return E_OUTOFMEMORY;
1124 strcpyW(strgtable[tabIndex++],bSlash);
1126 i++;
1129 else {
1131 for(j=0; str[i]!=0 && str[i]!=bSlash[0] ; i++,j++)
1132 word[j]=str[i];
1134 word[j]=0;
1136 strgtable[tabIndex]=CoTaskMemAlloc(sizeof(WCHAR)*(j+1));
1138 if (strgtable[tabIndex]==NULL)
1139 return E_OUTOFMEMORY;
1141 strcpyW(strgtable[tabIndex++],word);
1144 strgtable[tabIndex]=NULL;
1146 *stringTable=strgtable;
1148 return tabIndex;
1151 /******************************************************************************
1152 * FileMoniker_RelativePathTo
1153 ******************************************************************************/
1154 HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
1156 IBindCtx *bind;
1157 HRESULT res;
1158 LPOLESTR str1=0,str2=0,*tabStr1=0,*tabStr2=0,relPath=0;
1159 DWORD len1=0,len2=0,sameIdx=0,j=0;
1160 static const WCHAR back[] ={'.','.','\\',0};
1162 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
1164 if (ppmkRelPath==NULL)
1165 return E_POINTER;
1167 if (pmOther==NULL)
1168 return E_INVALIDARG;
1170 res=CreateBindCtx(0,&bind);
1171 if (FAILED(res))
1172 return res;
1174 res=IMoniker_GetDisplayName(iface,bind,NULL,&str1);
1175 if (FAILED(res))
1176 return res;
1177 res=IMoniker_GetDisplayName(pmOther,bind,NULL,&str2);
1178 if (FAILED(res))
1179 return res;
1181 len1=FileMonikerImpl_DecomposePath(str1,&tabStr1);
1182 len2=FileMonikerImpl_DecomposePath(str2,&tabStr2);
1184 if (FAILED(len1) || FAILED(len2))
1185 return E_OUTOFMEMORY;
1187 /* count the number of similar items from the begin of the two paths */
1188 for(sameIdx=0; ( (tabStr1[sameIdx]!=NULL) &&
1189 (tabStr2[sameIdx]!=NULL) &&
1190 (lstrcmpiW(tabStr1[sameIdx],tabStr2[sameIdx])==0)); sameIdx++);
1192 /* begin the construction of relativePath */
1193 /* if the two paths have a consecutive similar item from the begin ! the relativePath will be composed */
1194 /* by "..\\" in the begin */
1195 relPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(1+lstrlenW(str1)+lstrlenW(str2)));
1197 *relPath=0;
1199 if (len2>0 && !(len1==1 && len2==1 && sameIdx==0))
1200 for(j=sameIdx;(tabStr1[j] != NULL); j++)
1201 if (*tabStr1[j]!='\\')
1202 strcatW(relPath,back);
1204 /* add items of the second path (similar items with the first path are not included) to the relativePath */
1205 for(j=sameIdx;tabStr2[j]!=NULL;j++)
1206 strcatW(relPath,tabStr2[j]);
1208 res=CreateFileMoniker(relPath,ppmkRelPath);
1210 for(j=0; tabStr1[j]!=NULL;j++)
1211 CoTaskMemFree(tabStr1[j]);
1212 for(j=0; tabStr2[j]!=NULL;j++)
1213 CoTaskMemFree(tabStr2[j]);
1214 CoTaskMemFree(tabStr1);
1215 CoTaskMemFree(tabStr2);
1216 CoTaskMemFree(str1);
1217 CoTaskMemFree(str2);
1218 HeapFree(GetProcessHeap(),0,relPath);
1220 if (len1==0 || len2==0 || (len1==1 && len2==1 && sameIdx==0))
1221 return MK_S_HIM;
1223 return res;
1226 /******************************************************************************
1227 * FileMoniker_GetDisplayName
1228 ******************************************************************************/
1229 HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,
1230 IBindCtx* pbc,
1231 IMoniker* pmkToLeft,
1232 LPOLESTR *ppszDisplayName)
1234 ICOM_THIS(FileMonikerImpl,iface);
1236 int len=lstrlenW(This->filePathName);
1238 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
1240 if (ppszDisplayName==NULL)
1241 return E_POINTER;
1243 if (pmkToLeft!=NULL)
1244 return E_INVALIDARG;
1246 *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
1247 if (*ppszDisplayName==NULL)
1248 return E_OUTOFMEMORY;
1250 strcpyW(*ppszDisplayName,This->filePathName);
1252 return S_OK;
1255 /******************************************************************************
1256 * FileMoniker_ParseDisplayName
1257 ******************************************************************************/
1258 HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,
1259 IBindCtx* pbc,
1260 IMoniker* pmkToLeft,
1261 LPOLESTR pszDisplayName,
1262 ULONG* pchEaten,
1263 IMoniker** ppmkOut)
1265 FIXME("(%p,%p,%p,%p,%p,%p),stub!\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
1266 return E_NOTIMPL;
1269 /******************************************************************************
1270 * FileMoniker_IsSystemMoniker
1271 ******************************************************************************/
1272 HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
1274 TRACE("(%p,%p)\n",iface,pwdMksys);
1276 if (!pwdMksys)
1277 return E_POINTER;
1279 (*pwdMksys)=MKSYS_FILEMONIKER;
1281 return S_OK;
1284 /*******************************************************************************
1285 * FileMonikerIROTData_QueryInterface
1286 *******************************************************************************/
1287 HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
1290 ICOM_THIS_From_IROTData(IMoniker, iface);
1292 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
1294 return FileMonikerImpl_QueryInterface(This, riid, ppvObject);
1297 /***********************************************************************
1298 * FileMonikerIROTData_AddRef
1300 ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData *iface)
1302 ICOM_THIS_From_IROTData(IMoniker, iface);
1304 TRACE("(%p)\n",This);
1306 return FileMonikerImpl_AddRef(This);
1309 /***********************************************************************
1310 * FileMonikerIROTData_Release
1312 ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface)
1314 ICOM_THIS_From_IROTData(IMoniker, iface);
1316 TRACE("(%p)\n",This);
1318 return FileMonikerImpl_Release(This);
1321 /******************************************************************************
1322 * FileMonikerIROTData_GetComparaisonData
1323 ******************************************************************************/
1324 HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
1325 BYTE* pbData,
1326 ULONG cbMax,
1327 ULONG* pcbData)
1329 FIXME("(),stub!\n");
1330 return E_NOTIMPL;
1333 /******************************************************************************
1334 * CreateFileMoniker (OLE32.@)
1335 ******************************************************************************/
1336 HRESULT WINAPI CreateFileMoniker(LPCOLESTR lpszPathName, LPMONIKER * ppmk)
1338 FileMonikerImpl* newFileMoniker = 0;
1339 HRESULT hr = E_FAIL;
1340 IID riid=IID_IMoniker;
1342 TRACE("(%p,%p)\n",lpszPathName,ppmk);
1344 if (ppmk==NULL)
1345 return E_POINTER;
1347 if(lpszPathName==NULL)
1348 return MK_E_SYNTAX;
1350 *ppmk=0;
1352 newFileMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(FileMonikerImpl));
1354 if (newFileMoniker == 0)
1355 return E_OUTOFMEMORY;
1357 hr = FileMonikerImpl_Construct(newFileMoniker,lpszPathName);
1359 if (SUCCEEDED(hr))
1360 hr = FileMonikerImpl_QueryInterface((IMoniker*)newFileMoniker,&riid,(void**)ppmk);
1361 else
1362 HeapFree(GetProcessHeap(),0,newFileMoniker);
1364 return hr;