Got rid of the Wine internal lstrcpy* functions and of winestring.h.
[wine/gsoc_dplay.git] / dlls / ole32 / filemoniker.c
blob283f31b8f9b43c85f7503a85ff27b55525221a33
1 /***************************************************************************************
2 * FileMonikers implementation
4 * Copyright 1999 Noomen Hamza
5 ***************************************************************************************/
7 #include <assert.h>
8 #include "winbase.h"
9 #include "winerror.h"
10 #include "wine/unicode.h"
11 #include "debugtools.h"
12 #include "objbase.h"
13 #include "wine/obj_storage.h"
14 #include "wine/obj_moniker.h"
15 #include "wine/obj_base.h"
17 #include "compobj_private.h"
19 DEFAULT_DEBUG_CHANNEL(ole);
21 /* filemoniker data structure */
22 typedef struct FileMonikerImpl{
24 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
26 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
27 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
29 ICOM_VTABLE(IROTData)* lpvtbl2; /* VTable relative to the IROTData interface.*/
31 ULONG ref; /* reference counter for this object */
33 LPOLESTR filePathName; /* path string identified by this filemoniker */
35 } FileMonikerImpl;
37 /********************************************************************************/
38 /* FileMoniker prototype functions : */
40 /* IUnknown prototype functions */
41 static HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
42 static ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface);
43 static ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface);
45 /* IPersist prototype functions */
46 static HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
48 /* IPersistStream prototype functions */
49 static HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface);
50 static HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface, IStream* pStm);
51 static HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
52 static HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
54 /* IMoniker prototype functions */
55 static HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
56 static HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
57 static HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
58 static HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
59 static HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
60 static HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
61 static HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
62 static HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
63 static HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime);
64 static HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
65 static HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
66 static HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
67 static HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
68 static HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
69 static HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
71 /********************************************************************************/
72 /* IROTData prototype functions */
74 /* IUnknown prototype functions */
75 static HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
76 static ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData* iface);
77 static ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface);
79 /* IROTData prototype function */
80 static HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
82 /* Local function used by filemoniker implementation */
83 HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* iface, LPCOLESTR lpszPathName);
84 HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* iface);
85 int WINAPI FileMonikerImpl_DecomposePath(LPOLESTR str, LPOLESTR** tabStr);
88 /********************************************************************************/
89 /* Virtual function table for the FileMonikerImpl class witch include Ipersist,*/
90 /* IPersistStream and IMoniker functions. */
91 static ICOM_VTABLE(IMoniker) VT_FileMonikerImpl =
93 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
94 FileMonikerImpl_QueryInterface,
95 FileMonikerImpl_AddRef,
96 FileMonikerImpl_Release,
97 FileMonikerImpl_GetClassID,
98 FileMonikerImpl_IsDirty,
99 FileMonikerImpl_Load,
100 FileMonikerImpl_Save,
101 FileMonikerImpl_GetSizeMax,
102 FileMonikerImpl_BindToObject,
103 FileMonikerImpl_BindToStorage,
104 FileMonikerImpl_Reduce,
105 FileMonikerImpl_ComposeWith,
106 FileMonikerImpl_Enum,
107 FileMonikerImpl_IsEqual,
108 FileMonikerImpl_Hash,
109 FileMonikerImpl_IsRunning,
110 FileMonikerImpl_GetTimeOfLastChange,
111 FileMonikerImpl_Inverse,
112 FileMonikerImpl_CommonPrefixWith,
113 FileMonikerImpl_RelativePathTo,
114 FileMonikerImpl_GetDisplayName,
115 FileMonikerImpl_ParseDisplayName,
116 FileMonikerImpl_IsSystemMoniker
119 /********************************************************************************/
120 /* Virtual function table for the IROTData class. */
121 static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
123 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
124 FileMonikerROTDataImpl_QueryInterface,
125 FileMonikerROTDataImpl_AddRef,
126 FileMonikerROTDataImpl_Release,
127 FileMonikerROTDataImpl_GetComparaisonData
130 /*******************************************************************************
131 * FileMoniker_QueryInterface
132 *******************************************************************************/
133 HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
135 ICOM_THIS(FileMonikerImpl,iface);
137 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
139 /* Perform a sanity check on the parameters.*/
140 if ( (This==0) || (ppvObject==0) )
141 return E_INVALIDARG;
143 /* Initialize the return parameter */
144 *ppvObject = 0;
146 /* Compare the riid with the interface IDs implemented by this object.*/
147 if (IsEqualIID(&IID_IUnknown, riid) ||
148 IsEqualIID(&IID_IPersist, riid) ||
149 IsEqualIID(&IID_IPersistStream,riid) ||
150 IsEqualIID(&IID_IMoniker, riid)
152 *ppvObject = iface;
154 else if (IsEqualIID(&IID_IROTData, riid))
155 *ppvObject = (IROTData*)&(This->lpvtbl2);
157 /* Check that we obtained an interface.*/
158 if ((*ppvObject)==0)
159 return E_NOINTERFACE;
161 /* Query Interface always increases the reference count by one when it is successful */
162 FileMonikerImpl_AddRef(iface);
164 return S_OK;
167 /******************************************************************************
168 * FileMoniker_AddRef
169 ******************************************************************************/
170 ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface)
172 ICOM_THIS(FileMonikerImpl,iface);
174 TRACE("(%p)\n",iface);
176 return ++(This->ref);
179 /******************************************************************************
180 * FileMoniker_Release
181 ******************************************************************************/
182 ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface)
184 ICOM_THIS(FileMonikerImpl,iface);
186 TRACE("(%p)\n",iface);
188 This->ref--;
190 /* destroy the object if there's no more reference on it */
191 if (This->ref==0){
193 FileMonikerImpl_Destroy(This);
195 return 0;
197 return This->ref;;
200 /******************************************************************************
201 * FileMoniker_GetClassID
202 ******************************************************************************/
203 HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface,
204 CLSID *pClassID)/* Pointer to CLSID of object */
206 TRACE("(%p,%p),stub!\n",iface,pClassID);
208 if (pClassID==NULL)
209 return E_POINTER;
211 *pClassID = CLSID_FileMoniker;
213 return S_OK;
216 /******************************************************************************
217 * FileMoniker_IsDirty
218 ******************************************************************************/
219 HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface)
221 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
222 method in the OLE-provided moniker interfaces always return S_FALSE because
223 their internal state never changes. */
225 TRACE("(%p)\n",iface);
227 return S_FALSE;
230 /******************************************************************************
231 * FileMoniker_Load
232 ******************************************************************************/
233 HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface,IStream* pStm)
235 HRESULT res;
236 CHAR* filePathA;
237 WCHAR* filePathW;
238 ULONG bread;
239 WORD wbuffer;
240 DWORD dwbuffer,length,i,doubleLenHex,doubleLenDec;
242 ICOM_THIS(FileMonikerImpl,iface);
244 TRACE("(%p,%p)\n",iface,pStm);
246 /* this function locate and read from the stream the filePath string writen by FileMonikerImpl_Save */
248 /* first WORD is non significative */
249 res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
250 if (bread!=sizeof(WORD) || wbuffer!=0)
251 return E_FAIL;
253 /* read filePath string length (plus one) */
254 res=IStream_Read(pStm,&length,sizeof(DWORD),&bread);
255 if (bread != sizeof(DWORD))
256 return E_FAIL;
258 /* read filePath string */
259 filePathA=HeapAlloc(GetProcessHeap(),0,length);
260 res=IStream_Read(pStm,filePathA,length,&bread);
261 if (bread != length)
262 return E_FAIL;
264 /* read the first constant */
265 IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
266 if (bread != sizeof(DWORD) || dwbuffer != 0xDEADFFFF)
267 return E_FAIL;
269 length--;
271 for(i=0;i<10;i++){
272 res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
273 if (bread!=sizeof(WORD) || wbuffer!=0)
274 return E_FAIL;
277 if (length>8)
278 length=0;
280 doubleLenHex=doubleLenDec=2*length;
281 if (length > 5)
282 doubleLenDec+=6;
284 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
285 if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenDec)
286 return E_FAIL;
288 if (length==0)
289 return res;
291 res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
292 if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenHex)
293 return E_FAIL;
295 res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
296 if (bread!=sizeof(WORD) || wbuffer!=0x3)
297 return E_FAIL;
299 filePathW=HeapAlloc(GetProcessHeap(),0,(length+1)*sizeof(WCHAR));
300 filePathW[length]=0;
301 res=IStream_Read(pStm,filePathW,doubleLenHex,&bread);
302 if (bread!=doubleLenHex)
303 return E_FAIL;
305 if (This->filePathName!=NULL)
306 HeapFree(GetProcessHeap(),0,This->filePathName);
308 This->filePathName=filePathW;
310 HeapFree(GetProcessHeap(),0,filePathA);
312 return res;
315 /******************************************************************************
316 * FileMoniker_Save
317 ******************************************************************************/
318 HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface,
319 IStream* pStm,/* poniter to the stream where the object is to be saved */
320 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
322 /* this function saves data of this object. In the begining I thougth that I have just to write
323 * the filePath string on Stream. But, when I tested this function whith windows programs samples !
324 * I noted that it was not the case. So I analysed data writen by this function on Windows system and
325 * what did this function do exactly ! but I have no idear a bout its logic !
326 * I guessed data who must be writen on stream wich is:
327 * 1) WORD constant:zero 2) length of the path string ("\0" included) 3) path string type A
328 * 4) DWORD constant : 0xDEADFFFF 5) ten WORD constant: zero 6) DWORD: double-length of the the path
329 * string type W ("\0" not included) 7) WORD constant: 0x3 8) filePath unicode string.
330 * if the length(filePath) > 8 or.length(filePath) == 8 stop at step 5)
333 ICOM_THIS(FileMonikerImpl,iface);
335 HRESULT res;
336 LPOLESTR filePathW=This->filePathName;
337 CHAR* filePathA;
338 DWORD len;
340 DWORD constant1 = 0xDEADFFFF; /* these constants are detected after analysing the data structure writen by */
341 WORD constant2 = 0x3; /* FileMoniker_Save function in a windows program system */
343 WORD zero=0;
344 DWORD doubleLenHex;
345 DWORD doubleLenDec;
346 int i=0;
348 TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty);
350 if (pStm==NULL)
351 return E_POINTER;
353 /* write a DWORD seted to 0 : constant */
354 res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
356 /* write length of filePath string ( "\0" included )*/
357 len = WideCharToMultiByte( CP_ACP, 0, filePathW, -1, NULL, 0, NULL, NULL );
358 res=IStream_Write(pStm,&len,sizeof(DWORD),NULL);
360 /* write filePath string type A */
361 filePathA=HeapAlloc(GetProcessHeap(),0,len);
362 WideCharToMultiByte( CP_ACP, 0, filePathW, -1, filePathA, len, NULL, NULL );
363 res=IStream_Write(pStm,filePathA,len,NULL);
364 HeapFree(GetProcessHeap(),0,filePathA);
366 /* write a DWORD seted to 0xDEADFFFF: constant */
367 res=IStream_Write(pStm,&constant1,sizeof(DWORD),NULL);
369 len--;
370 /* write 10 times a DWORD seted to 0 : constants */
371 for(i=0;i<10;i++)
372 res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
374 if (len>8)
375 len=0;
377 doubleLenHex=doubleLenDec=2*len;
378 if (len > 5)
379 doubleLenDec+=6;
381 /* write double-length of the path string ( "\0" included )*/
382 res=IStream_Write(pStm,&doubleLenDec,sizeof(DWORD),NULL);
384 if (len==0)
385 return res;
387 /* write double-length (hexa representation) of the path string ( "\0" included ) */
388 res=IStream_Write(pStm,&doubleLenHex,sizeof(DWORD),NULL);
390 /* write a WORD seted to 0x3: constant */
391 res=IStream_Write(pStm,&constant2,sizeof(WORD),NULL);
393 /* write path unicode string */
394 res=IStream_Write(pStm,filePathW,doubleLenHex,NULL);
396 return res;
399 /******************************************************************************
400 * FileMoniker_GetSizeMax
401 ******************************************************************************/
402 HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface,
403 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
405 ICOM_THIS(FileMonikerImpl,iface);
406 DWORD len=lstrlenW(This->filePathName);
407 DWORD sizeMAx;
409 TRACE("(%p,%p)\n",iface,pcbSize);
411 if (pcbSize!=NULL)
412 return E_POINTER;
414 /* for more details see FileMonikerImpl_Save coments */
416 sizeMAx = sizeof(WORD) + /* first WORD is 0 */
417 sizeof(DWORD)+ /* length of filePath including "\0" in the end of the string */
418 (len+1)+ /* filePath string */
419 sizeof(DWORD)+ /* constant : 0xDEADFFFF */
420 10*sizeof(WORD)+ /* 10 zero WORD */
421 sizeof(DWORD); /* size of the unicode filePath: "\0" not included */
423 if (len==0 || len > 8)
424 return S_OK;
426 sizeMAx += sizeof(DWORD)+ /* size of the unicode filePath: "\0" not included */
427 sizeof(WORD)+ /* constant : 0x3 */
428 len*sizeof(WCHAR); /* unicde filePath string */
430 pcbSize->s.LowPart=sizeMAx;
431 pcbSize->s.HighPart=0;
433 return S_OK;
436 /******************************************************************************
437 * FileMoniker_Construct (local function)
438 *******************************************************************************/
439 HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* This, LPCOLESTR lpszPathName)
441 int nb=0,i;
442 int sizeStr=lstrlenW(lpszPathName);
443 LPOLESTR *tabStr=0;
444 WCHAR twoPoint[]={'.','.',0};
445 WCHAR bkSlash[]={'\\',0};
446 BYTE addBkSlash;
448 TRACE("(%p,%p)\n",This,lpszPathName);
450 /* Initialize the virtual fgunction table. */
451 This->lpvtbl1 = &VT_FileMonikerImpl;
452 This->lpvtbl2 = &VT_ROTDataImpl;
453 This->ref = 0;
455 This->filePathName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1));
457 if (This->filePathName==NULL)
458 return E_OUTOFMEMORY;
460 strcpyW(This->filePathName,lpszPathName);
462 nb=FileMonikerImpl_DecomposePath(This->filePathName,&tabStr);
464 if (nb > 0 ){
466 addBkSlash=1;
467 if (lstrcmpW(tabStr[0],twoPoint)!=0)
468 addBkSlash=0;
469 else
470 for(i=0;i<nb;i++){
472 if ( (lstrcmpW(tabStr[i],twoPoint)!=0) && (lstrcmpW(tabStr[i],bkSlash)!=0) ){
473 addBkSlash=0;
474 break;
476 else
478 if (lstrcmpW(tabStr[i],bkSlash)==0 && i<nb-1 && lstrcmpW(tabStr[i+1],bkSlash)==0){
479 *tabStr[i]=0;
480 sizeStr--;
481 addBkSlash=0;
482 break;
486 if (lstrcmpW(tabStr[nb-1],bkSlash)==0)
487 addBkSlash=0;
489 This->filePathName=HeapReAlloc(GetProcessHeap(),0,This->filePathName,(sizeStr+1)*sizeof(WCHAR));
491 *This->filePathName=0;
493 for(i=0;tabStr[i]!=NULL;i++)
494 strcatW(This->filePathName,tabStr[i]);
496 if (addBkSlash)
497 strcatW(This->filePathName,bkSlash);
500 for(i=0; tabStr[i]!=NULL;i++)
501 CoTaskMemFree(tabStr[i]);
502 CoTaskMemFree(tabStr);
504 return S_OK;
507 /******************************************************************************
508 * FileMoniker_Destroy (local function)
509 *******************************************************************************/
510 HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* This)
512 TRACE("(%p)\n",This);
514 if (This->filePathName!=NULL)
515 HeapFree(GetProcessHeap(),0,This->filePathName);
517 HeapFree(GetProcessHeap(),0,This);
519 return S_OK;
522 /******************************************************************************
523 * FileMoniker_BindToObject
524 ******************************************************************************/
525 HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,
526 IBindCtx* pbc,
527 IMoniker* pmkToLeft,
528 REFIID riid,
529 VOID** ppvResult)
531 HRESULT res=E_FAIL;
532 CLSID clsID;
533 IUnknown* pObj=0;
534 IRunningObjectTable *prot=0;
535 IPersistFile *ppf=0;
536 IClassFactory *pcf=0;
537 IClassActivator *pca=0;
539 ICOM_THIS(FileMonikerImpl,iface);
541 *ppvResult=0;
543 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
545 if(pmkToLeft==NULL){
547 res=IBindCtx_GetRunningObjectTable(pbc,&prot);
549 if (SUCCEEDED(res)){
550 /* if the requested class was loaded befor ! we dont need to reload it */
551 res = IRunningObjectTable_GetObject(prot,iface,&pObj);
553 if (res==S_FALSE){
554 /* first activation of this class */
555 res=GetClassFile(This->filePathName,&clsID);
556 if (SUCCEEDED(res)){
558 res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IPersistFile,(void**)&ppf);
559 if (SUCCEEDED(res)){
561 res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
562 if (SUCCEEDED(res)){
564 pObj=(IUnknown*)ppf;
565 IUnknown_AddRef(pObj);
572 else{
573 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassFactory,(void**)&pcf);
575 if (res==E_NOINTERFACE){
577 res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassActivator,(void**)&pca);
579 if (res==E_NOINTERFACE)
580 return MK_E_INTERMEDIATEINTERFACENOTSUPPORTED;
582 if (pcf!=NULL){
584 IClassFactory_CreateInstance(pcf,NULL,&IID_IPersistFile,(void**)ppf);
586 res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
588 if (SUCCEEDED(res)){
590 pObj=(IUnknown*)ppf;
591 IUnknown_AddRef(pObj);
594 if (pca!=NULL){
596 FIXME("()");
598 /*res=GetClassFile(This->filePathName,&clsID);
600 if (SUCCEEDED(res)){
602 res=IClassActivator_GetClassObject(pca,&clsID,CLSCTX_ALL,0,&IID_IPersistFile,(void**)&ppf);
604 if (SUCCEEDED(res)){
606 pObj=(IUnknown*)ppf;
607 IUnknown_AddRef(pObj);
613 if (pObj!=NULL){
614 /* get the requested interface from the loaded class */
615 res= IUnknown_QueryInterface(pObj,riid,ppvResult);
617 IBindCtx_RegisterObjectBound(pbc,(IUnknown*)*ppvResult);
619 IUnknown_Release(pObj);
622 if (prot!=NULL)
623 IRunningObjectTable_Release(prot);
625 if (ppf!=NULL)
626 IPersistFile_Release(ppf);
628 if (pca!=NULL)
629 IClassActivator_Release(pca);
631 if (pcf!=NULL)
632 IClassFactory_Release(pcf);
634 return res;
637 /******************************************************************************
638 * FileMoniker_BindToStorage
639 ******************************************************************************/
640 HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,
641 IBindCtx* pbc,
642 IMoniker* pmkToLeft,
643 REFIID riid,
644 VOID** ppvObject)
646 LPOLESTR filePath=0;
647 IStorage *pstg=0;
648 HRESULT res;
650 TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
652 if (pmkToLeft==NULL){
654 if (IsEqualIID(&IID_IStorage, riid)){
656 /* get the file name */
657 FileMonikerImpl_GetDisplayName(iface,pbc,pmkToLeft,&filePath);
659 /* verifie if the file contains a storage object */
660 res=StgIsStorageFile(filePath);
662 if(res==S_OK){
664 res=StgOpenStorage(filePath,NULL,STGM_READWRITE|STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
666 if (SUCCEEDED(res)){
668 *ppvObject=pstg;
670 IStorage_AddRef(pstg);
672 return res;
675 CoTaskMemFree(filePath);
677 else
678 if ( (IsEqualIID(&IID_IStream, riid)) || (IsEqualIID(&IID_ILockBytes, riid)) )
680 return E_UNSPEC;
681 else
683 return E_NOINTERFACE;
685 else {
687 FIXME("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
689 return E_NOTIMPL;
691 return res;
694 /******************************************************************************
695 * FileMoniker_Reduce
696 ******************************************************************************/
697 HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,
698 IBindCtx* pbc,
699 DWORD dwReduceHowFar,
700 IMoniker** ppmkToLeft,
701 IMoniker** ppmkReduced)
703 TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
705 if (ppmkReduced==NULL)
706 return E_POINTER;
708 FileMonikerImpl_AddRef(iface);
710 *ppmkReduced=iface;
712 return MK_S_REDUCED_TO_SELF;
714 /******************************************************************************
715 * FileMoniker_ComposeWith
716 ******************************************************************************/
717 HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,
718 IMoniker* pmkRight,
719 BOOL fOnlyIfNotGeneric,
720 IMoniker** ppmkComposite)
722 HRESULT res;
723 LPOLESTR str1=0,str2=0,*strDec1=0,*strDec2=0,newStr=0;
724 WCHAR twoPoint[]={'.','.',0};
725 WCHAR bkSlash[]={'\\',0};
726 IBindCtx *bind=0;
727 int i=0,j=0,lastIdx1=0,lastIdx2=0;
728 DWORD mkSys;
730 TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
732 if (ppmkComposite==NULL)
733 return E_POINTER;
735 if (pmkRight==NULL)
736 return E_INVALIDARG;
738 *ppmkComposite=0;
740 IMoniker_IsSystemMoniker(pmkRight,&mkSys);
742 /* check if we have two filemonikers to compose or not */
743 if(mkSys==MKSYS_FILEMONIKER){
745 CreateBindCtx(0,&bind);
747 FileMonikerImpl_GetDisplayName(iface,bind,NULL,&str1);
748 IMoniker_GetDisplayName(pmkRight,bind,NULL,&str2);
750 /* decompose pathnames of the two monikers : (to prepare the path merge operation ) */
751 lastIdx1=FileMonikerImpl_DecomposePath(str1,&strDec1)-1;
752 lastIdx2=FileMonikerImpl_DecomposePath(str2,&strDec2)-1;
754 if ((lastIdx1==-1 && lastIdx2>-1)||(lastIdx1==1 && lstrcmpW(strDec1[0],twoPoint)==0))
755 return MK_E_SYNTAX;
757 if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0)
758 lastIdx1--;
760 /* for etch "..\" in the left of str2 remove the right element from str1 */
761 for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ) ;i+=2){
763 lastIdx1-=2;
766 /* the length of the composed path string is raised by the sum of the two paths lengths */
767 newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
769 if (newStr==NULL)
770 return E_OUTOFMEMORY;
772 /* new path is the concatenation of the rest of str1 and str2 */
773 for(*newStr=0,j=0;j<=lastIdx1;j++)
774 strcatW(newStr,strDec1[j]);
776 if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
777 strcatW(newStr,bkSlash);
779 for(j=i;j<=lastIdx2;j++)
780 strcatW(newStr,strDec2[j]);
782 /* create a new moniker with the new string */
783 res=CreateFileMoniker(newStr,ppmkComposite);
785 /* free all strings space memory used by this function */
786 HeapFree(GetProcessHeap(),0,newStr);
788 for(i=0; strDec1[i]!=NULL;i++)
789 CoTaskMemFree(strDec1[i]);
790 for(i=0; strDec2[i]!=NULL;i++)
791 CoTaskMemFree(strDec2[i]);
792 CoTaskMemFree(strDec1);
793 CoTaskMemFree(strDec2);
795 CoTaskMemFree(str1);
796 CoTaskMemFree(str2);
798 return res;
800 else if(mkSys==MKSYS_ANTIMONIKER){
802 *ppmkComposite=NULL;
803 return S_OK;
805 else if (fOnlyIfNotGeneric){
807 *ppmkComposite=NULL;
808 return MK_E_NEEDGENERIC;
810 else
812 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
815 /******************************************************************************
816 * FileMoniker_Enum
817 ******************************************************************************/
818 HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
820 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
822 if (ppenumMoniker == NULL)
823 return E_POINTER;
825 *ppenumMoniker = NULL;
827 return S_OK;
830 /******************************************************************************
831 * FileMoniker_IsEqual
832 ******************************************************************************/
833 HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
835 ICOM_THIS(FileMonikerImpl,iface);
836 CLSID clsid;
837 LPOLESTR filePath;
838 IBindCtx* bind;
839 HRESULT res;
841 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
843 if (pmkOtherMoniker==NULL)
844 return S_FALSE;
846 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
848 if (!IsEqualCLSID(&clsid,&CLSID_FileMoniker))
850 return S_FALSE;
852 res=CreateBindCtx(0,&bind);
853 if (FAILED(res))
854 return res;
856 IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&filePath);
858 if (lstrcmpiW(filePath,
859 This->filePathName)!=0)
861 return S_FALSE;
863 return S_OK;
866 /******************************************************************************
867 * FileMoniker_Hash
868 ******************************************************************************/
869 HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
871 ICOM_THIS(FileMonikerImpl,iface);
873 int h = 0,i,skip,len;
874 int off = 0;
875 LPOLESTR val;
877 if (pdwHash==NULL)
878 return E_POINTER;
880 val = This->filePathName;
881 len = lstrlenW(val);
883 if (len < 16) {
884 for (i = len ; i > 0; i--) {
885 h = (h * 37) + val[off++];
887 } else {
888 /* only sample some characters */
889 skip = len / 8;
890 for (i = len ; i > 0; i -= skip, off += skip) {
891 h = (h * 39) + val[off];
895 *pdwHash=h;
897 return S_OK;
900 /******************************************************************************
901 * FileMoniker_IsRunning
902 ******************************************************************************/
903 HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,
904 IBindCtx* pbc,
905 IMoniker* pmkToLeft,
906 IMoniker* pmkNewlyRunning)
908 IRunningObjectTable* rot;
909 HRESULT res;
911 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
913 if ( (pmkNewlyRunning!=NULL) && (IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK) )
914 return S_OK;
916 if (pbc==NULL)
917 return E_POINTER;
919 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
921 if (FAILED(res))
922 return res;
924 res = IRunningObjectTable_IsRunning(rot,iface);
926 IRunningObjectTable_Release(rot);
928 return res;
931 /******************************************************************************
932 * FileMoniker_GetTimeOfLastChange
933 ******************************************************************************/
934 HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
935 IBindCtx* pbc,
936 IMoniker* pmkToLeft,
937 FILETIME* pFileTime)
939 ICOM_THIS(FileMonikerImpl,iface);
940 IRunningObjectTable* rot;
941 HRESULT res;
942 WIN32_FILE_ATTRIBUTE_DATA info;
944 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pFileTime);
946 if (pFileTime==NULL)
947 return E_POINTER;
949 if (pmkToLeft!=NULL)
950 return E_INVALIDARG;
952 res=IBindCtx_GetRunningObjectTable(pbc,&rot);
954 if (FAILED(res))
955 return res;
957 res= IRunningObjectTable_GetTimeOfLastChange(rot,iface,pFileTime);
959 if (FAILED(res)){ /* the moniker is not registred */
961 if (!GetFileAttributesExW(This->filePathName,GetFileExInfoStandard,&info))
962 return MK_E_NOOBJECT;
964 *pFileTime=info.ftLastWriteTime;
967 return S_OK;
970 /******************************************************************************
971 * FileMoniker_Inverse
972 ******************************************************************************/
973 HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
976 TRACE("(%p,%p)\n",iface,ppmk);
978 return CreateAntiMoniker(ppmk);
981 /******************************************************************************
982 * FileMoniker_CommonPrefixWith
983 ******************************************************************************/
984 HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
987 LPOLESTR pathThis,pathOther,*stringTable1,*stringTable2,commonPath;
988 IBindCtx *pbind;
989 DWORD mkSys;
990 ULONG nb1,nb2,i,sameIdx;
991 BOOL machimeNameCase=FALSE;
993 if (ppmkPrefix==NULL)
994 return E_POINTER;
996 if (pmkOther==NULL)
997 return E_INVALIDARG;
999 *ppmkPrefix=0;
1001 /* check if we have the same type of moniker */
1002 IMoniker_IsSystemMoniker(pmkOther,&mkSys);
1004 if(mkSys==MKSYS_FILEMONIKER){
1006 CreateBindCtx(0,&pbind);
1008 /* create a string based on common part of the two paths */
1010 IMoniker_GetDisplayName(iface,pbind,NULL,&pathThis);
1011 IMoniker_GetDisplayName(pmkOther,pbind,NULL,&pathOther);
1013 nb1=FileMonikerImpl_DecomposePath(pathThis,&stringTable1);
1014 nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2);
1016 if (nb1==0 || nb2==0)
1017 return MK_E_NOPREFIX;
1019 commonPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
1021 *commonPath=0;
1023 for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
1024 (stringTable2[sameIdx]!=NULL) &&
1025 (lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
1027 if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
1029 machimeNameCase=TRUE;
1031 for(i=2;i<sameIdx;i++)
1033 if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
1034 machimeNameCase=FALSE;
1035 break;
1039 if (machimeNameCase && *stringTable1[sameIdx-1]=='\\')
1040 sameIdx--;
1042 if (machimeNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
1043 return MK_E_NOPREFIX;
1045 for(i=0;i<sameIdx;i++)
1046 strcatW(commonPath,stringTable1[i]);
1048 for(i=0;i<nb1;i++)
1049 CoTaskMemFree(stringTable1[i]);
1051 CoTaskMemFree(stringTable1);
1053 for(i=0;i<nb2;i++)
1054 CoTaskMemFree(stringTable2[i]);
1056 CoTaskMemFree(stringTable2);
1058 HeapFree(GetProcessHeap(),0,commonPath);
1060 return CreateFileMoniker(commonPath,ppmkPrefix);
1062 else
1063 return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
1066 /******************************************************************************
1067 * DecomposePath (local function)
1068 ******************************************************************************/
1069 int WINAPI FileMonikerImpl_DecomposePath(LPOLESTR str, LPOLESTR** stringTable)
1071 WCHAR bSlash[] = {'\\',0};
1072 WCHAR word[MAX_PATH];
1073 int i=0,j,tabIndex=0;
1074 LPOLESTR *strgtable ;
1076 int len=lstrlenW(str);
1078 strgtable =CoTaskMemAlloc(len*sizeof(LPOLESTR));
1080 if (strgtable==NULL)
1081 return E_OUTOFMEMORY;
1083 while(str[i]!=0){
1085 if(str[i]==bSlash[0]){
1087 strgtable[tabIndex]=CoTaskMemAlloc(2*sizeof(WCHAR));
1089 if (strgtable[tabIndex]==NULL)
1090 return E_OUTOFMEMORY;
1092 strcpyW(strgtable[tabIndex++],bSlash);
1094 i++;
1097 else {
1099 for(j=0; str[i]!=0 && str[i]!=bSlash[0] ; i++,j++)
1100 word[j]=str[i];
1102 word[j]=0;
1104 strgtable[tabIndex]=CoTaskMemAlloc(sizeof(WCHAR)*(j+1));
1106 if (strgtable[tabIndex]==NULL)
1107 return E_OUTOFMEMORY;
1109 strcpyW(strgtable[tabIndex++],word);
1112 strgtable[tabIndex]=NULL;
1114 *stringTable=strgtable;
1116 return tabIndex;
1119 /******************************************************************************
1120 * FileMoniker_RelativePathTo
1121 ******************************************************************************/
1122 HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
1124 IBindCtx *bind;
1125 HRESULT res;
1126 LPOLESTR str1=0,str2=0,*tabStr1=0,*tabStr2=0,relPath=0;
1127 DWORD len1=0,len2=0,sameIdx=0,j=0;
1128 WCHAR back[] ={'.','.','\\',0};
1130 TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
1132 if (ppmkRelPath==NULL)
1133 return E_POINTER;
1135 if (pmOther==NULL)
1136 return E_INVALIDARG;
1138 res=CreateBindCtx(0,&bind);
1139 if (FAILED(res))
1140 return res;
1142 res=IMoniker_GetDisplayName(iface,bind,NULL,&str1);
1143 if (FAILED(res))
1144 return res;
1145 res=IMoniker_GetDisplayName(pmOther,bind,NULL,&str2);
1146 if (FAILED(res))
1147 return res;
1149 len1=FileMonikerImpl_DecomposePath(str1,&tabStr1);
1150 len2=FileMonikerImpl_DecomposePath(str2,&tabStr2);
1152 if (FAILED(len1) || FAILED(len2))
1153 return E_OUTOFMEMORY;
1155 /* count the number of similar items from the begin of the two paths */
1156 for(sameIdx=0; ( (tabStr1[sameIdx]!=NULL) &&
1157 (tabStr2[sameIdx]!=NULL) &&
1158 (lstrcmpiW(tabStr1[sameIdx],tabStr2[sameIdx])==0)); sameIdx++);
1160 /* begin the construction of relativePath */
1161 /* if the two paths have a consecutive similar item from the begin ! the relativePath will be composed */
1162 /* by "..\\" in the begin */
1163 relPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(1+lstrlenW(str1)+lstrlenW(str2)));
1165 *relPath=0;
1167 if (len2>0 && !(len1==1 && len2==1 && sameIdx==0))
1168 for(j=sameIdx;(tabStr1[j] != NULL); j++)
1169 if (*tabStr1[j]!='\\')
1170 strcatW(relPath,back);
1172 /* add items of the second path (similar items with the first path are not included) to the relativePath */
1173 for(j=sameIdx;tabStr2[j]!=NULL;j++)
1174 strcatW(relPath,tabStr2[j]);
1176 res=CreateFileMoniker(relPath,ppmkRelPath);
1178 for(j=0; tabStr1[j]!=NULL;j++)
1179 CoTaskMemFree(tabStr1[j]);
1180 for(j=0; tabStr2[j]!=NULL;j++)
1181 CoTaskMemFree(tabStr2[j]);
1182 CoTaskMemFree(tabStr1);
1183 CoTaskMemFree(tabStr2);
1184 CoTaskMemFree(str1);
1185 CoTaskMemFree(str2);
1186 HeapFree(GetProcessHeap(),0,relPath);
1188 if (len1==0 || len2==0 || (len1==1 && len2==1 && sameIdx==0))
1189 return MK_S_HIM;
1191 return res;
1194 /******************************************************************************
1195 * FileMoniker_GetDisplayName
1196 ******************************************************************************/
1197 HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,
1198 IBindCtx* pbc,
1199 IMoniker* pmkToLeft,
1200 LPOLESTR *ppszDisplayName)
1202 ICOM_THIS(FileMonikerImpl,iface);
1204 int len=lstrlenW(This->filePathName);
1206 TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
1208 if (ppszDisplayName==NULL)
1209 return E_POINTER;
1211 if (pmkToLeft!=NULL)
1212 return E_INVALIDARG;
1214 *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
1215 if (*ppszDisplayName==NULL)
1216 return E_OUTOFMEMORY;
1218 strcpyW(*ppszDisplayName,This->filePathName);
1220 return S_OK;
1223 /******************************************************************************
1224 * FileMoniker_ParseDisplayName
1225 ******************************************************************************/
1226 HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,
1227 IBindCtx* pbc,
1228 IMoniker* pmkToLeft,
1229 LPOLESTR pszDisplayName,
1230 ULONG* pchEaten,
1231 IMoniker** ppmkOut)
1233 FIXME("(%p,%p,%p,%p,%p,%p),stub!\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
1234 return E_NOTIMPL;
1237 /******************************************************************************
1238 * FileMoniker_IsSystemMonker
1239 ******************************************************************************/
1240 HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
1242 TRACE("(%p,%p)\n",iface,pwdMksys);
1244 if (!pwdMksys)
1245 return E_POINTER;
1247 (*pwdMksys)=MKSYS_FILEMONIKER;
1249 return S_OK;
1252 /*******************************************************************************
1253 * FileMonikerIROTData_QueryInterface
1254 *******************************************************************************/
1255 HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
1258 ICOM_THIS_From_IROTData(IMoniker, iface);
1260 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
1262 return FileMonikerImpl_QueryInterface(This, riid, ppvObject);
1265 /***********************************************************************
1266 * FileMonikerIROTData_AddRef
1268 ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData *iface)
1270 ICOM_THIS_From_IROTData(IMoniker, iface);
1272 TRACE("(%p)\n",This);
1274 return FileMonikerImpl_AddRef(This);
1277 /***********************************************************************
1278 * FileMonikerIROTData_Release
1280 ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface)
1282 ICOM_THIS_From_IROTData(IMoniker, iface);
1284 TRACE("(%p)\n",This);
1286 return FileMonikerImpl_Release(This);
1289 /******************************************************************************
1290 * FileMonikerIROTData_GetComparaisonData
1291 ******************************************************************************/
1292 HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
1293 BYTE* pbData,
1294 ULONG cbMax,
1295 ULONG* pcbData)
1297 FIXME("(),stub!\n");
1298 return E_NOTIMPL;
1301 /******************************************************************************
1302 * CreateFileMoniker16
1303 ******************************************************************************/
1304 HRESULT WINAPI CreateFileMoniker16(LPCOLESTR16 lpszPathName,LPMONIKER* ppmk)
1307 FIXME("(%s,%p),stub!\n",lpszPathName,ppmk);
1308 return E_NOTIMPL;
1311 /******************************************************************************
1312 * CreateFileMoniker
1313 ******************************************************************************/
1314 HRESULT WINAPI CreateFileMoniker(LPCOLESTR lpszPathName, LPMONIKER * ppmk)
1316 FileMonikerImpl* newFileMoniker = 0;
1317 HRESULT hr = E_FAIL;
1318 IID riid=IID_IMoniker;
1320 TRACE("(%p,%p)\n",lpszPathName,ppmk);
1322 if (ppmk==NULL)
1323 return E_POINTER;
1325 if(lpszPathName==NULL)
1326 return MK_E_SYNTAX;
1328 *ppmk=0;
1330 newFileMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(FileMonikerImpl));
1332 if (newFileMoniker == 0)
1333 return E_OUTOFMEMORY;
1335 hr = FileMonikerImpl_Construct(newFileMoniker,lpszPathName);
1337 if (SUCCEEDED(hr))
1338 hr = FileMonikerImpl_QueryInterface((IMoniker*)newFileMoniker,&riid,(void**)ppmk);
1339 else
1340 HeapFree(GetProcessHeap(),0,newFileMoniker);
1342 return hr;