Fixed HeapRealloc typo.
[wine/wine64.git] / dlls / ole32 / filemoniker.c
blob117a2070c123b8f5469eb0b1e14ad0337742dd78
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->s.LowPart=sizeMAx;
463 pcbSize->s.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 WCHAR twoPoint[]={'.','.',0};
477 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)) )
712 return E_UNSPEC;
713 else
715 return E_NOINTERFACE;
717 else {
719 FIXME("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
721 return E_NOTIMPL;
723 return res;
726 /******************************************************************************
727 * FileMoniker_Reduce
728 ******************************************************************************/
729 HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,
730 IBindCtx* pbc,
731 DWORD dwReduceHowFar,
732 IMoniker** ppmkToLeft,
733 IMoniker** ppmkReduced)
735 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
737 if (ppmkReduced==NULL)
738 return E_POINTER;
740 FileMonikerImpl_AddRef(iface);
742 *ppmkReduced=iface;
744 return MK_S_REDUCED_TO_SELF;
746 /******************************************************************************
747 * FileMoniker_ComposeWith
748 ******************************************************************************/
749 HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,
750 IMoniker* pmkRight,
751 BOOL fOnlyIfNotGeneric,
752 IMoniker** ppmkComposite)
754 HRESULT res;
755 LPOLESTR str1=0,str2=0,*strDec1=0,*strDec2=0,newStr=0;
756 WCHAR twoPoint[]={'.','.',0};
757 WCHAR bkSlash[]={'\\',0};
758 IBindCtx *bind=0;
759 int i=0,j=0,lastIdx1=0,lastIdx2=0;
760 DWORD mkSys;
762 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
764 if (ppmkComposite==NULL)
765 return E_POINTER;
767 if (pmkRight==NULL)
768 return E_INVALIDARG;
770 *ppmkComposite=0;
772 IMoniker_IsSystemMoniker(pmkRight,&mkSys);
774 /* check if we have two filemonikers to compose or not */
775 if(mkSys==MKSYS_FILEMONIKER){
777 CreateBindCtx(0,&bind);
779 FileMonikerImpl_GetDisplayName(iface,bind,NULL,&str1);
780 IMoniker_GetDisplayName(pmkRight,bind,NULL,&str2);
782 /* decompose pathnames of the two monikers : (to prepare the path merge operation ) */
783 lastIdx1=FileMonikerImpl_DecomposePath(str1,&strDec1)-1;
784 lastIdx2=FileMonikerImpl_DecomposePath(str2,&strDec2)-1;
786 if ((lastIdx1==-1 && lastIdx2>-1)||(lastIdx1==1 && lstrcmpW(strDec1[0],twoPoint)==0))
787 return MK_E_SYNTAX;
789 if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0)
790 lastIdx1--;
792 /* for etch "..\" in the left of str2 remove the right element from str1 */
793 for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ) ;i+=2){
795 lastIdx1-=2;
798 /* the length of the composed path string is raised by the sum of the two paths lengths */
799 newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
801 if (newStr==NULL)
802 return E_OUTOFMEMORY;
804 /* new path is the concatenation of the rest of str1 and str2 */
805 for(*newStr=0,j=0;j<=lastIdx1;j++)
806 strcatW(newStr,strDec1[j]);
808 if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
809 strcatW(newStr,bkSlash);
811 for(j=i;j<=lastIdx2;j++)
812 strcatW(newStr,strDec2[j]);
814 /* create a new moniker with the new string */
815 res=CreateFileMoniker(newStr,ppmkComposite);
817 /* free all strings space memory used by this function */
818 HeapFree(GetProcessHeap(),0,newStr);
820 for(i=0; strDec1[i]!=NULL;i++)
821 CoTaskMemFree(strDec1[i]);
822 for(i=0; strDec2[i]!=NULL;i++)
823 CoTaskMemFree(strDec2[i]);
824 CoTaskMemFree(strDec1);
825 CoTaskMemFree(strDec2);
827 CoTaskMemFree(str1);
828 CoTaskMemFree(str2);
830 return res;
832 else if(mkSys==MKSYS_ANTIMONIKER){
834 *ppmkComposite=NULL;
835 return S_OK;
837 else if (fOnlyIfNotGeneric){
839 *ppmkComposite=NULL;
840 return MK_E_NEEDGENERIC;
842 else
844 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
847 /******************************************************************************
848 * FileMoniker_Enum
849 ******************************************************************************/
850 HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
852 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
854 if (ppenumMoniker == NULL)
855 return E_POINTER;
857 *ppenumMoniker = NULL;
859 return S_OK;
862 /******************************************************************************
863 * FileMoniker_IsEqual
864 ******************************************************************************/
865 HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
867 ICOM_THIS(FileMonikerImpl,iface);
868 CLSID clsid;
869 LPOLESTR filePath;
870 IBindCtx* bind;
871 HRESULT res;
873 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
875 if (pmkOtherMoniker==NULL)
876 return S_FALSE;
878 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
880 if (!IsEqualCLSID(&clsid,&CLSID_FileMoniker))
881 return S_FALSE;
883 res = CreateBindCtx(0,&bind);
884 if (FAILED(res)) return res;
886 if (SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&filePath))) {
887 int result = lstrcmpiW(filePath, This->filePathName);
888 CoTaskMemFree(filePath);
889 if ( result == 0 ) return S_OK;
891 return S_FALSE;
895 /******************************************************************************
896 * FileMoniker_Hash
897 ******************************************************************************/
898 HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
900 ICOM_THIS(FileMonikerImpl,iface);
902 int h = 0,i,skip,len;
903 int off = 0;
904 LPOLESTR val;
906 if (pdwHash==NULL)
907 return E_POINTER;
909 val = This->filePathName;
910 len = lstrlenW(val);
912 if (len < 16) {
913 for (i = len ; i > 0; i--) {
914 h = (h * 37) + val[off++];
916 } else {
917 /* only sample some characters */
918 skip = len / 8;
919 for (i = len ; i > 0; i -= skip, off += skip) {
920 h = (h * 39) + val[off];
924 *pdwHash=h;
926 return S_OK;
929 /******************************************************************************
930 * FileMoniker_IsRunning
931 ******************************************************************************/
932 HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,
933 IBindCtx* pbc,
934 IMoniker* pmkToLeft,
935 IMoniker* pmkNewlyRunning)
937 IRunningObjectTable* rot;
938 HRESULT res;
940 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
942 if ( (pmkNewlyRunning!=NULL) && (IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK) )
943 return S_OK;
945 if (pbc==NULL)
946 return E_POINTER;
948 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
950 if (FAILED(res))
951 return res;
953 res = IRunningObjectTable_IsRunning(rot,iface);
955 IRunningObjectTable_Release(rot);
957 return res;
960 /******************************************************************************
961 * FileMoniker_GetTimeOfLastChange
962 ******************************************************************************/
963 HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
964 IBindCtx* pbc,
965 IMoniker* pmkToLeft,
966 FILETIME* pFileTime)
968 ICOM_THIS(FileMonikerImpl,iface);
969 IRunningObjectTable* rot;
970 HRESULT res;
971 WIN32_FILE_ATTRIBUTE_DATA info;
973 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pFileTime);
975 if (pFileTime==NULL)
976 return E_POINTER;
978 if (pmkToLeft!=NULL)
979 return E_INVALIDARG;
981 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
983 if (FAILED(res))
984 return res;
986 res= IRunningObjectTable_GetTimeOfLastChange(rot,iface,pFileTime);
988 if (FAILED(res)){ /* the moniker is not registred */
990 if (!GetFileAttributesExW(This->filePathName,GetFileExInfoStandard,&info))
991 return MK_E_NOOBJECT;
993 *pFileTime=info.ftLastWriteTime;
996 return S_OK;
999 /******************************************************************************
1000 * FileMoniker_Inverse
1001 ******************************************************************************/
1002 HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
1005 TRACE("(%p,%p)\n",iface,ppmk);
1007 return CreateAntiMoniker(ppmk);
1010 /******************************************************************************
1011 * FileMoniker_CommonPrefixWith
1012 ******************************************************************************/
1013 HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
1016 LPOLESTR pathThis,pathOther,*stringTable1,*stringTable2,commonPath;
1017 IBindCtx *pbind;
1018 DWORD mkSys;
1019 ULONG nb1,nb2,i,sameIdx;
1020 BOOL machimeNameCase=FALSE;
1022 if (ppmkPrefix==NULL)
1023 return E_POINTER;
1025 if (pmkOther==NULL)
1026 return E_INVALIDARG;
1028 *ppmkPrefix=0;
1030 /* check if we have the same type of moniker */
1031 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
1033 if(mkSys==MKSYS_FILEMONIKER){
1034 HRESULT ret;
1036 CreateBindCtx(0,&pbind);
1038 /* create a string based on common part of the two paths */
1040 IMoniker_GetDisplayName(iface,pbind,NULL,&pathThis);
1041 IMoniker_GetDisplayName(pmkOther,pbind,NULL,&pathOther);
1043 nb1=FileMonikerImpl_DecomposePath(pathThis,&stringTable1);
1044 nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2);
1046 if (nb1==0 || nb2==0)
1047 return MK_E_NOPREFIX;
1049 commonPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
1051 *commonPath=0;
1053 for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
1054 (stringTable2[sameIdx]!=NULL) &&
1055 (lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
1057 if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
1059 machimeNameCase=TRUE;
1061 for(i=2;i<sameIdx;i++)
1063 if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
1064 machimeNameCase=FALSE;
1065 break;
1069 if (machimeNameCase && *stringTable1[sameIdx-1]=='\\')
1070 sameIdx--;
1072 if (machimeNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
1073 ret = MK_E_NOPREFIX;
1074 else
1076 for(i=0;i<sameIdx;i++)
1077 strcatW(commonPath,stringTable1[i]);
1079 for(i=0;i<nb1;i++)
1080 CoTaskMemFree(stringTable1[i]);
1082 CoTaskMemFree(stringTable1);
1084 for(i=0;i<nb2;i++)
1085 CoTaskMemFree(stringTable2[i]);
1087 CoTaskMemFree(stringTable2);
1089 ret = CreateFileMoniker(commonPath,ppmkPrefix);
1091 HeapFree(GetProcessHeap(),0,commonPath);
1092 return ret;
1094 else
1095 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
1098 /******************************************************************************
1099 * DecomposePath (local function)
1100 ******************************************************************************/
1101 int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable)
1103 WCHAR bSlash[] = {'\\',0};
1104 WCHAR word[MAX_PATH];
1105 int i=0,j,tabIndex=0;
1106 LPOLESTR *strgtable ;
1108 int len=lstrlenW(str);
1110 TRACE("%s, %p\n", debugstr_w(str), *stringTable);
1112 strgtable =CoTaskMemAlloc(len*sizeof(LPOLESTR));
1114 if (strgtable==NULL)
1115 return E_OUTOFMEMORY;
1117 while(str[i]!=0){
1119 if(str[i]==bSlash[0]){
1121 strgtable[tabIndex]=CoTaskMemAlloc(2*sizeof(WCHAR));
1123 if (strgtable[tabIndex]==NULL)
1124 return E_OUTOFMEMORY;
1126 strcpyW(strgtable[tabIndex++],bSlash);
1128 i++;
1131 else {
1133 for(j=0; str[i]!=0 && str[i]!=bSlash[0] ; i++,j++)
1134 word[j]=str[i];
1136 word[j]=0;
1138 strgtable[tabIndex]=CoTaskMemAlloc(sizeof(WCHAR)*(j+1));
1140 if (strgtable[tabIndex]==NULL)
1141 return E_OUTOFMEMORY;
1143 strcpyW(strgtable[tabIndex++],word);
1146 strgtable[tabIndex]=NULL;
1148 *stringTable=strgtable;
1150 return tabIndex;
1153 /******************************************************************************
1154 * FileMoniker_RelativePathTo
1155 ******************************************************************************/
1156 HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
1158 IBindCtx *bind;
1159 HRESULT res;
1160 LPOLESTR str1=0,str2=0,*tabStr1=0,*tabStr2=0,relPath=0;
1161 DWORD len1=0,len2=0,sameIdx=0,j=0;
1162 WCHAR back[] ={'.','.','\\',0};
1164 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
1166 if (ppmkRelPath==NULL)
1167 return E_POINTER;
1169 if (pmOther==NULL)
1170 return E_INVALIDARG;
1172 res=CreateBindCtx(0,&bind);
1173 if (FAILED(res))
1174 return res;
1176 res=IMoniker_GetDisplayName(iface,bind,NULL,&str1);
1177 if (FAILED(res))
1178 return res;
1179 res=IMoniker_GetDisplayName(pmOther,bind,NULL,&str2);
1180 if (FAILED(res))
1181 return res;
1183 len1=FileMonikerImpl_DecomposePath(str1,&tabStr1);
1184 len2=FileMonikerImpl_DecomposePath(str2,&tabStr2);
1186 if (FAILED(len1) || FAILED(len2))
1187 return E_OUTOFMEMORY;
1189 /* count the number of similar items from the begin of the two paths */
1190 for(sameIdx=0; ( (tabStr1[sameIdx]!=NULL) &&
1191 (tabStr2[sameIdx]!=NULL) &&
1192 (lstrcmpiW(tabStr1[sameIdx],tabStr2[sameIdx])==0)); sameIdx++);
1194 /* begin the construction of relativePath */
1195 /* if the two paths have a consecutive similar item from the begin ! the relativePath will be composed */
1196 /* by "..\\" in the begin */
1197 relPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(1+lstrlenW(str1)+lstrlenW(str2)));
1199 *relPath=0;
1201 if (len2>0 && !(len1==1 && len2==1 && sameIdx==0))
1202 for(j=sameIdx;(tabStr1[j] != NULL); j++)
1203 if (*tabStr1[j]!='\\')
1204 strcatW(relPath,back);
1206 /* add items of the second path (similar items with the first path are not included) to the relativePath */
1207 for(j=sameIdx;tabStr2[j]!=NULL;j++)
1208 strcatW(relPath,tabStr2[j]);
1210 res=CreateFileMoniker(relPath,ppmkRelPath);
1212 for(j=0; tabStr1[j]!=NULL;j++)
1213 CoTaskMemFree(tabStr1[j]);
1214 for(j=0; tabStr2[j]!=NULL;j++)
1215 CoTaskMemFree(tabStr2[j]);
1216 CoTaskMemFree(tabStr1);
1217 CoTaskMemFree(tabStr2);
1218 CoTaskMemFree(str1);
1219 CoTaskMemFree(str2);
1220 HeapFree(GetProcessHeap(),0,relPath);
1222 if (len1==0 || len2==0 || (len1==1 && len2==1 && sameIdx==0))
1223 return MK_S_HIM;
1225 return res;
1228 /******************************************************************************
1229 * FileMoniker_GetDisplayName
1230 ******************************************************************************/
1231 HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,
1232 IBindCtx* pbc,
1233 IMoniker* pmkToLeft,
1234 LPOLESTR *ppszDisplayName)
1236 ICOM_THIS(FileMonikerImpl,iface);
1238 int len=lstrlenW(This->filePathName);
1240 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
1242 if (ppszDisplayName==NULL)
1243 return E_POINTER;
1245 if (pmkToLeft!=NULL)
1246 return E_INVALIDARG;
1248 *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
1249 if (*ppszDisplayName==NULL)
1250 return E_OUTOFMEMORY;
1252 strcpyW(*ppszDisplayName,This->filePathName);
1254 return S_OK;
1257 /******************************************************************************
1258 * FileMoniker_ParseDisplayName
1259 ******************************************************************************/
1260 HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,
1261 IBindCtx* pbc,
1262 IMoniker* pmkToLeft,
1263 LPOLESTR pszDisplayName,
1264 ULONG* pchEaten,
1265 IMoniker** ppmkOut)
1267 FIXME("(%p,%p,%p,%p,%p,%p),stub!\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
1268 return E_NOTIMPL;
1271 /******************************************************************************
1272 * FileMoniker_IsSystemMoniker
1273 ******************************************************************************/
1274 HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
1276 TRACE("(%p,%p)\n",iface,pwdMksys);
1278 if (!pwdMksys)
1279 return E_POINTER;
1281 (*pwdMksys)=MKSYS_FILEMONIKER;
1283 return S_OK;
1286 /*******************************************************************************
1287 * FileMonikerIROTData_QueryInterface
1288 *******************************************************************************/
1289 HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
1292 ICOM_THIS_From_IROTData(IMoniker, iface);
1294 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
1296 return FileMonikerImpl_QueryInterface(This, riid, ppvObject);
1299 /***********************************************************************
1300 * FileMonikerIROTData_AddRef
1302 ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData *iface)
1304 ICOM_THIS_From_IROTData(IMoniker, iface);
1306 TRACE("(%p)\n",This);
1308 return FileMonikerImpl_AddRef(This);
1311 /***********************************************************************
1312 * FileMonikerIROTData_Release
1314 ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface)
1316 ICOM_THIS_From_IROTData(IMoniker, iface);
1318 TRACE("(%p)\n",This);
1320 return FileMonikerImpl_Release(This);
1323 /******************************************************************************
1324 * FileMonikerIROTData_GetComparaisonData
1325 ******************************************************************************/
1326 HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
1327 BYTE* pbData,
1328 ULONG cbMax,
1329 ULONG* pcbData)
1331 FIXME("(),stub!\n");
1332 return E_NOTIMPL;
1335 /******************************************************************************
1336 * CreateFileMoniker (OLE2.28)
1337 ******************************************************************************/
1338 HRESULT WINAPI CreateFileMoniker16(LPCOLESTR16 lpszPathName,LPMONIKER* ppmk)
1341 FIXME("(%s,%p),stub!\n",lpszPathName,ppmk);
1342 return E_NOTIMPL;
1345 /******************************************************************************
1346 * CreateFileMoniker (OLE32.@)
1347 ******************************************************************************/
1348 HRESULT WINAPI CreateFileMoniker(LPCOLESTR lpszPathName, LPMONIKER * ppmk)
1350 FileMonikerImpl* newFileMoniker = 0;
1351 HRESULT hr = E_FAIL;
1352 IID riid=IID_IMoniker;
1354 TRACE("(%p,%p)\n",lpszPathName,ppmk);
1356 if (ppmk==NULL)
1357 return E_POINTER;
1359 if(lpszPathName==NULL)
1360 return MK_E_SYNTAX;
1362 *ppmk=0;
1364 newFileMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(FileMonikerImpl));
1366 if (newFileMoniker == 0)
1367 return E_OUTOFMEMORY;
1369 hr = FileMonikerImpl_Construct(newFileMoniker,lpszPathName);
1371 if (SUCCEEDED(hr))
1372 hr = FileMonikerImpl_QueryInterface((IMoniker*)newFileMoniker,&riid,(void**)ppmk);
1373 else
1374 HeapFree(GetProcessHeap(),0,newFileMoniker);
1376 return hr;