4 * Copyright 1999 Ulrich Czekalla for Corel Corporation
5 * Copyright 2002 Huw D M Davies for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define COM_NO_WINDOWS_H
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
39 #include "urlmon_main.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
43 /* native urlmon.dll uses this key, too */
44 static const WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
46 /*static BOOL registered_wndclass = FALSE;*/
48 /* filemoniker data structure */
49 typedef struct URLMonikerImpl{
51 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
52 ICOM_VTABLE(IBinding)* lpvtbl2; /* VTable to IBinding interface */
54 ULONG ref; /* reference counter for this object */
56 LPOLESTR URLName; /* URL string identified by this URLmoniker */
60 HINTERNET hinternet, hconnect, hrequest;
63 /********************************************************************************/
64 /* URLMoniker prototype functions : */
66 /* IUnknown prototype functions */
67 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
68 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface);
69 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface);
71 /* IPersist prototype functions */
72 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
74 /* IPersistStream prototype functions */
75 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface);
76 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface, IStream* pStm);
77 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
78 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
80 /* IMoniker prototype functions */
81 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
82 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
83 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
84 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
85 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
86 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
87 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
88 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
89 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime);
90 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
91 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
92 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
93 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
94 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
95 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
97 /* IBinding interface to moniker */
98 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject);
99 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface);
100 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface);
101 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface);
102 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface);
103 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface);
104 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority);
105 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority);
106 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved);
108 /* Local function used by urlmoniker implementation */
109 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* iface, LPCOLESTR lpszURL);
110 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* iface);
112 /********************************************************************************/
113 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
114 /* IPersistStream and IMoniker functions. */
115 static ICOM_VTABLE(IMoniker) VT_URLMonikerImpl =
117 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
118 URLMonikerImpl_QueryInterface,
119 URLMonikerImpl_AddRef,
120 URLMonikerImpl_Release,
121 URLMonikerImpl_GetClassID,
122 URLMonikerImpl_IsDirty,
125 URLMonikerImpl_GetSizeMax,
126 URLMonikerImpl_BindToObject,
127 URLMonikerImpl_BindToStorage,
128 URLMonikerImpl_Reduce,
129 URLMonikerImpl_ComposeWith,
131 URLMonikerImpl_IsEqual,
133 URLMonikerImpl_IsRunning,
134 URLMonikerImpl_GetTimeOfLastChange,
135 URLMonikerImpl_Inverse,
136 URLMonikerImpl_CommonPrefixWith,
137 URLMonikerImpl_RelativePathTo,
138 URLMonikerImpl_GetDisplayName,
139 URLMonikerImpl_ParseDisplayName,
140 URLMonikerImpl_IsSystemMoniker
143 static ICOM_VTABLE(IBinding) VTBinding_URLMonikerImpl =
145 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
146 URLMonikerImpl_IBinding_QueryInterface,
147 URLMonikerImpl_IBinding_AddRef,
148 URLMonikerImpl_IBinding_Release,
149 URLMonikerImpl_IBinding_Abort,
150 URLMonikerImpl_IBinding_Suspend,
151 URLMonikerImpl_IBinding_Resume,
152 URLMonikerImpl_IBinding_SetPriority,
153 URLMonikerImpl_IBinding_GetPriority,
154 URLMonikerImpl_IBinding_GetBindResult
158 /*******************************************************************************
159 * URLMoniker_QueryInterface
160 *******************************************************************************/
161 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
163 ICOM_THIS(URLMonikerImpl,iface);
165 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
167 /* Perform a sanity check on the parameters.*/
168 if ( (This==0) || (ppvObject==0) )
171 /* Initialize the return parameter */
174 /* Compare the riid with the interface IDs implemented by this object.*/
175 if (IsEqualIID(&IID_IUnknown, riid) ||
176 IsEqualIID(&IID_IPersist, riid) ||
177 IsEqualIID(&IID_IPersistStream,riid) ||
178 IsEqualIID(&IID_IMoniker, riid)
182 /* Check that we obtained an interface.*/
184 return E_NOINTERFACE;
186 /* Query Interface always increases the reference count by one when it is successful */
187 URLMonikerImpl_AddRef(iface);
192 /******************************************************************************
194 ******************************************************************************/
195 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
197 ICOM_THIS(URLMonikerImpl,iface);
199 TRACE("(%p)\n",This);
201 return ++(This->ref);
204 /******************************************************************************
206 ******************************************************************************/
207 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
209 ICOM_THIS(URLMonikerImpl,iface);
211 TRACE("(%p)\n",This);
215 /* destroy the object if there's no more reference on it */
218 URLMonikerImpl_Destroy(This);
225 /******************************************************************************
226 * URLMoniker_GetClassID
227 ******************************************************************************/
228 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface,
229 CLSID *pClassID)/* Pointer to CLSID of object */
231 ICOM_THIS(URLMonikerImpl,iface);
233 TRACE("(%p,%p)\n",This,pClassID);
237 /* Windows always returns CLSID_StdURLMoniker */
238 *pClassID = CLSID_StdURLMoniker;
242 /******************************************************************************
244 ******************************************************************************/
245 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface)
247 ICOM_THIS(URLMonikerImpl,iface);
248 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
249 method in the OLE-provided moniker interfaces always return S_FALSE because
250 their internal state never changes. */
252 TRACE("(%p)\n",This);
257 /******************************************************************************
261 * Writes a ULONG containing length of unicode string, followed
262 * by that many unicode characters
263 ******************************************************************************/
264 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
266 ICOM_THIS(URLMonikerImpl,iface);
271 TRACE("(%p,%p)\n",This,pStm);
276 res = IStream_Read(pStm, &len, sizeof(ULONG), &got);
278 if(got == sizeof(ULONG)) {
280 HeapFree(GetProcessHeap(), 0, This->URLName);
281 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(len+1));
285 res = IStream_Read(pStm, This->URLName, len, NULL);
286 This->URLName[len] = 0;
295 /******************************************************************************
297 ******************************************************************************/
298 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
299 IStream* pStm,/* pointer to the stream where the object is to be saved */
300 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
302 ICOM_THIS(URLMonikerImpl,iface);
306 TRACE("(%p,%p,%d)\n",This,pStm,fClearDirty);
311 len = strlenW(This->URLName);
312 res=IStream_Write(pStm,&len,sizeof(ULONG),NULL);
314 res=IStream_Write(pStm,&This->URLName,len*sizeof(WCHAR),NULL);
319 /******************************************************************************
320 * URLMoniker_GetSizeMax
321 ******************************************************************************/
322 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
323 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
325 ICOM_THIS(URLMonikerImpl,iface);
327 TRACE("(%p,%p)\n",This,pcbSize);
332 pcbSize->u.LowPart = sizeof(ULONG) + (strlenW(This->URLName) * sizeof(WCHAR));
333 pcbSize->u.HighPart = 0;
337 /******************************************************************************
338 * URLMoniker_Construct (local function)
339 *******************************************************************************/
340 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszURLName)
342 int sizeStr = strlenW(lpszURLName);
344 TRACE("(%p,%s)\n",This,debugstr_w(lpszURLName));
345 memset(This, 0, sizeof(*This));
347 /* Initialize the virtual function table. */
348 This->lpvtbl1 = &VT_URLMonikerImpl;
349 This->lpvtbl2 = &VTBinding_URLMonikerImpl;
352 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1));
354 if (This->URLName==NULL)
355 return E_OUTOFMEMORY;
357 strcpyW(This->URLName,lpszURLName);
364 /******************************************************************************
365 * URLMoniker_Destroy (local function)
366 *******************************************************************************/
367 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* This)
369 TRACE("(%p)\n",This);
371 if (This->URLName!=NULL)
372 HeapFree(GetProcessHeap(),0,This->URLName);
374 HeapFree(GetProcessHeap(),0,This);
379 /******************************************************************************
380 * URLMoniker_BindToObject
381 ******************************************************************************/
382 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
388 ICOM_THIS(URLMonikerImpl,iface);
392 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),
399 enum {OnProgress, OnDataAvailable} callback;
400 } URLMON_CallbackData;
404 static LRESULT CALLBACK URLMON_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
406 return DefWindowProcA(hwnd, msg, wparam, lparam);
409 static void PostOnProgress(URLMonikerImpl *This, UINT progress, UINT maxprogress, DWORD status, LPCWSTR *str)
413 static void CALLBACK URLMON_InternetCallback(HINTERNET hinet, /*DWORD_PTR*/ DWORD context, DWORD status,
414 void *status_info, DWORD status_info_len)
416 URLMonikerImpl *This = (URLMonikerImpl *)context;
417 TRACE("handle %p this %p status %08lx\n", hinet, This, status);
419 if(This->filesize == -1) {
421 case INTERNET_STATUS_RESOLVING_NAME:
422 PostOnProgess(This, 0, 0, BINDSTATUS_FINDINGRESOURCE, status_info);
424 case INTERNET_STATUS_CONNECTING_TO_SERVER:
425 PostOnProgress(This, 0, 0, BINDSTATUS_CONNECTING, NULL);
427 case INTERNET_STATUS_SENDING_REQUEST:
428 PostOnProgress(This, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
430 case INTERNET_REQUEST_COMPLETE:
432 DWORD len, lensz = sizeof(len);
434 HttpQueryInfoW(hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
435 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
436 This->filesize = len;
445 /******************************************************************************
446 * URLMoniker_BindToStorage
447 ******************************************************************************/
448 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
454 ICOM_THIS(URLMonikerImpl,iface);
456 IBindStatusCallback *pbscb;
460 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),ppvObject);
462 FIXME("pmkToLeft != NULL\n");
465 if(!IsEqualIID(&IID_IStream, riid)) {
466 FIXME("unsupported iid\n");
470 /* FIXME This is a bad hack (tm). We should clearly download to a temporary file.
471 We also need to implement IStream ourselves so that IStream_Read can return
474 hres = CreateStreamOnHGlobal(0, TRUE, (IStream**)ppvObject);
477 if(SUCCEEDED(hres)) {
478 TRACE("Created dummy stream...\n");
480 hres = IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown**)&pbscb);
481 if(SUCCEEDED(hres)) {
482 TRACE("Got IBindStatusCallback...\n");
484 memset(&bi, 0, sizeof(bi));
485 bi.cbSize = sizeof(bi);
487 hres = IBindStatusCallback_GetBindInfo(pbscb, &bindf, &bi);
488 if(SUCCEEDED(hres)) {
491 DWORD len, lensz = sizeof(len), total_read = 0;
492 LARGE_INTEGER last_read_pos;
496 TRACE("got bindinfo. bindf = %08lx extrainfo = %s bindinfof = %08lx bindverb = %08lx iid %s\n",
497 bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
498 hres = IBindStatusCallback_OnStartBinding(pbscb, 0, (IBinding*)&This->lpvtbl2);
499 TRACE("OnStartBinding rets %08lx\n", hres);
502 if(!registered_wndclass) {
503 WNDCLASSA urlmon_wndclass = {0, URLMON_WndProc,0, 0, URLMON_hInstance, 0, 0, 0, NULL, "URLMON_Callback_Window_Class"};
504 RegisterClassA(&urlmon_wndclass);
505 registered_wndclass = TRUE;
508 This->hwndCallback = CreateWindowA("URLMON_Callback_Window_Class", NULL, 0, 0, 0, 0, 0, 0, 0,
509 URLMON_hInstance, NULL);
512 memset(&url, 0, sizeof(url));
513 url.dwStructSize = sizeof(url);
514 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = 1;
515 InternetCrackUrlW(This->URLName, 0, 0, &url);
516 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
517 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
518 host[url.dwHostNameLength] = '\0';
519 path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
520 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
521 path[url.dwUrlPathLength] = '\0';
523 This->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0 /*INTERNET_FLAG_ASYNC*/);
524 /* InternetSetStatusCallback(This->hinternet, URLMON_InternetCallback);*/
526 This->hconnect = InternetConnectW(This->hinternet, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
527 INTERNET_SERVICE_HTTP, 0, (DWORD)This);
528 This->hrequest = HttpOpenRequestW(This->hconnect, NULL, path, NULL, NULL, NULL, 0, (DWORD)This);
530 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, 0x22, NULL);
531 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
532 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
533 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
534 hres = E_OUTOFMEMORY; /* FIXME */
535 if(HttpSendRequestW(This->hrequest, NULL, 0, NULL, 0)) {
538 HttpQueryInfoW(This->hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
540 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
542 last_read_pos.u.LowPart = last_read_pos.u.HighPart = 0;
547 fmt.tymed = TYMED_ISTREAM;
548 stg.tymed = TYMED_ISTREAM;
549 stg.u.pstm = *(IStream**)ppvObject;
550 stg.pUnkForRelease = NULL;
556 if(InternetReadFile(This->hrequest, buf, sizeof(buf), &bufread)) {
557 TRACE("read %ld bytes %s...\n", bufread, debugstr_an(buf, 10));
558 if(bufread == 0) break;
559 IStream_Write(*(IStream**)ppvObject, buf, bufread, &written);
560 total_read += bufread;
561 IStream_Seek(*(IStream**)ppvObject, last_read_pos, STREAM_SEEK_SET, NULL);
562 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, (total_read == bufread) ?
563 BINDSTATUS_BEGINDOWNLOADDATA :
564 BINDSTATUS_DOWNLOADINGDATA, NULL);
565 hres = IBindStatusCallback_OnDataAvailable(pbscb,
566 (total_read == bufread) ? BSCF_FIRSTDATANOTIFICATION :
567 BSCF_INTERMEDIATEDATANOTIFICATION,
568 total_read, &fmt, &stg);
569 last_read_pos.u.LowPart += bufread; /* FIXME */
573 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, BINDSTATUS_ENDDOWNLOADDATA, NULL);
574 hres = IBindStatusCallback_OnDataAvailable(pbscb, BSCF_LASTDATANOTIFICATION, total_read, &fmt, &stg);
575 TRACE("OnDataAvail rets %08lx\n", hres);
576 hres = IBindStatusCallback_OnStopBinding(pbscb, S_OK, NULL);
577 TRACE("OnStop rets %08lx\n", hres);
580 InternetCloseHandle(This->hrequest);
581 InternetCloseHandle(This->hconnect);
582 InternetCloseHandle(This->hinternet);
589 /******************************************************************************
591 ******************************************************************************/
592 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
594 DWORD dwReduceHowFar,
595 IMoniker** ppmkToLeft,
596 IMoniker** ppmkReduced)
598 ICOM_THIS(URLMonikerImpl,iface);
600 TRACE("(%p,%p,%ld,%p,%p)\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
605 URLMonikerImpl_AddRef(iface);
606 *ppmkReduced = iface;
607 return MK_S_REDUCED_TO_SELF;
610 /******************************************************************************
611 * URLMoniker_ComposeWith
612 ******************************************************************************/
613 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
615 BOOL fOnlyIfNotGeneric,
616 IMoniker** ppmkComposite)
618 ICOM_THIS(URLMonikerImpl,iface);
619 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
624 /******************************************************************************
626 ******************************************************************************/
627 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
629 ICOM_THIS(URLMonikerImpl,iface);
630 TRACE("(%p,%d,%p)\n",This,fForward,ppenumMoniker);
635 /* Does not support sub-monikers */
636 *ppenumMoniker = NULL;
640 /******************************************************************************
642 ******************************************************************************/
643 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
645 ICOM_THIS(URLMonikerImpl,iface);
651 TRACE("(%p,%p)\n",This,pmkOtherMoniker);
653 if(pmkOtherMoniker==NULL)
656 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
658 if(!IsEqualCLSID(&clsid,&CLSID_StdURLMoniker))
661 res = CreateBindCtx(0,&bind);
666 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&urlPath))) {
667 int result = lstrcmpiW(urlPath, This->URLName);
668 CoTaskMemFree(urlPath);
672 IUnknown_Release(bind);
677 /******************************************************************************
679 ******************************************************************************/
680 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
682 ICOM_THIS(URLMonikerImpl,iface);
684 int h = 0,i,skip,len;
688 TRACE("(%p,%p)\n",This,pdwHash);
697 for(i = len ; i > 0; i--) {
698 h = (h * 37) + val[off++];
702 /* only sample some characters */
704 for(i = len; i > 0; i -= skip, off += skip) {
705 h = (h * 39) + val[off];
712 /******************************************************************************
713 * URLMoniker_IsRunning
714 ******************************************************************************/
715 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
718 IMoniker* pmkNewlyRunning)
720 ICOM_THIS(URLMonikerImpl,iface);
721 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
726 /******************************************************************************
727 * URLMoniker_GetTimeOfLastChange
728 ******************************************************************************/
729 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
734 ICOM_THIS(URLMonikerImpl,iface);
735 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
740 /******************************************************************************
742 ******************************************************************************/
743 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
745 ICOM_THIS(URLMonikerImpl,iface);
746 TRACE("(%p,%p)\n",This,ppmk);
748 return MK_E_NOINVERSE;
751 /******************************************************************************
752 * URLMoniker_CommonPrefixWith
753 ******************************************************************************/
754 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
756 ICOM_THIS(URLMonikerImpl,iface);
757 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
762 /******************************************************************************
763 * URLMoniker_RelativePathTo
764 ******************************************************************************/
765 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
767 ICOM_THIS(URLMonikerImpl,iface);
768 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
773 /******************************************************************************
774 * URLMoniker_GetDisplayName
775 ******************************************************************************/
776 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
779 LPOLESTR *ppszDisplayName)
781 ICOM_THIS(URLMonikerImpl,iface);
785 TRACE("(%p,%p,%p,%p)\n",This,pbc,pmkToLeft,ppszDisplayName);
790 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
791 then look at pmkToLeft to try and complete the URL
793 len = lstrlenW(This->URLName)+1;
794 *ppszDisplayName = CoTaskMemAlloc(len*sizeof(WCHAR));
795 if(!*ppszDisplayName)
796 return E_OUTOFMEMORY;
797 lstrcpyW(*ppszDisplayName, This->URLName);
801 /******************************************************************************
802 * URLMoniker_ParseDisplayName
803 ******************************************************************************/
804 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
807 LPOLESTR pszDisplayName,
811 ICOM_THIS(URLMonikerImpl,iface);
812 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
817 /******************************************************************************
818 * URLMoniker_IsSystemMoniker
819 ******************************************************************************/
820 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
822 ICOM_THIS(URLMonikerImpl,iface);
823 TRACE("(%p,%p)\n",This,pwdMksys);
828 *pwdMksys = MKSYS_URLMONIKER;
832 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject)
834 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
836 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
838 /* Perform a sanity check on the parameters.*/
839 if ( (This==0) || (ppvObject==0) )
842 /* Initialize the return parameter */
845 /* Compare the riid with the interface IDs implemented by this object.*/
846 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid))
849 /* Check that we obtained an interface.*/
851 return E_NOINTERFACE;
853 /* Query Interface always increases the reference count by one when it is successful */
854 URLMonikerImpl_IBinding_AddRef(iface);
860 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface)
862 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
863 TRACE("(%p)\n",This);
865 return URLMonikerImpl_AddRef((IMoniker*)This);
868 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface)
870 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
871 TRACE("(%p)\n",This);
873 return URLMonikerImpl_Release((IMoniker*)This);
876 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface)
878 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
879 FIXME("(%p): stub\n", This);
884 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
886 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
887 FIXME("(%p)->(%s, %p, %p, %p): stub\n", This, debugstr_guid(pclsidProtocol), pdwResult, pszResult, pdwReserved);
892 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority)
894 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
895 FIXME("(%p)->(%p): stub\n", This, pnPriority);
900 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface)
902 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
903 FIXME("(%p): stub\n", This);
908 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority)
910 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
911 FIXME("(%p)->(%ld): stub\n", This, nPriority);
916 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface)
918 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
919 FIXME("(%p): stub\n", This);
924 /***********************************************************************
925 * CreateAsyncBindCtx (URLMON.@)
927 HRESULT WINAPI CreateAsyncBindCtx(DWORD reserved, IBindStatusCallback *callback,
928 IEnumFORMATETC *format, IBindCtx **pbind)
933 /***********************************************************************
934 * CreateAsyncBindCtxEx (URLMON.@)
936 * Create an asynchronous bind context.
941 HRESULT WINAPI CreateAsyncBindCtxEx(IBindCtx *ibind, DWORD options,
942 IBindStatusCallback *callback, IEnumFORMATETC *format, IBindCtx** pbind,
945 FIXME("stub, returns failure\n");
950 /***********************************************************************
951 * CreateURLMoniker (URLMON.@)
953 * Create a url moniker.
956 * pmkContext [I] Context
957 * szURL [I] Url to create the moniker for
958 * ppmk [O] Destination for created moniker.
961 * Success: S_OK. ppmk contains the created IMoniker object.
962 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
963 * E_OUTOFMEMORY if memory allocation fails.
965 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
969 IID iid = IID_IMoniker;
971 TRACE("(%p, %s, %p)\n", pmkContext, debugstr_w(szURL), ppmk);
973 if (NULL != pmkContext)
974 FIXME("Non-null pmkContext not implemented\n");
976 if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj))))
977 return E_OUTOFMEMORY;
979 hres = URLMonikerImpl_Construct(obj, szURL);
981 hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &iid, (void**)ppmk);
983 HeapFree(GetProcessHeap(), 0, obj);
988 /***********************************************************************
989 * CoInternetGetSession (URLMON.@)
991 * Create a new internet session and return an IInternetSession interface
995 * dwSessionMode [I] Mode for the internet session
996 * ppIInternetSession [O] Destination for creates IInternetSession object
997 * dwReserved [I] Reserved, must be 0.
1000 * Success: S_OK. ppIInternetSession contains the IInternetSession interface.
1001 * Failure: E_INVALIDARG, if any argument is invalid, or
1002 * E_OUTOFMEMORY if memory allocation fails.
1004 HRESULT WINAPI CoInternetGetSession(DWORD dwSessionMode, /*IInternetSession*/void **ppIInternetSession, DWORD dwReserved)
1006 FIXME("(%ld, %p, %ld): stub\n", dwSessionMode, ppIInternetSession, dwReserved);
1009 ERR("dwSessionMode: %ld, must be zero\n", dwSessionMode);
1013 ERR("dwReserved: %ld, must be zero\n", dwReserved);
1016 *ppIInternetSession=NULL;
1017 return E_OUTOFMEMORY;
1020 /***********************************************************************
1021 * CoInternetQueryInfo (URLMON.@)
1023 * Retrieves information relevant to a specified URL
1027 * S_FALSE buffer too small
1028 * INET_E_QUERYOPTIONUNKNOWN invalid option
1031 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
1032 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD * pcbBuffer,
1035 FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl),
1036 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
1040 static BOOL URLMON_IsBinary(LPVOID pBuffer, DWORD cbSize)
1042 int binarycount = 0;
1044 unsigned char *buff = pBuffer;
1045 for(i=0; i<cbSize; i++) {
1049 return binarycount > (cbSize-binarycount);
1052 /***********************************************************************
1053 * FindMimeFromData (URLMON.@)
1055 * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
1058 * See http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp
1060 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
1061 DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
1062 LPWSTR* ppwzMimeOut, DWORD dwReserved)
1064 static const WCHAR szBinaryMime[] = {'a','p','p','l','i','c','a','t','i','o','n','/','o','c','t','e','t','-','s','t','r','e','a','m','\0'};
1065 static const WCHAR szTextMime[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
1066 static const WCHAR szContentType[] = {'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
1067 WCHAR szTmpMime[256];
1068 LPCWSTR mimeType = NULL;
1071 TRACE("(%p,%s,%p,%ld,%s,0x%lx,%p,0x%lx)\n", pBC, debugstr_w(pwzUrl), pBuffer, cbSize,
1072 debugstr_w(pwzMimeProposed), dwMimeFlags, ppwzMimeOut, dwReserved);
1074 if((!pwzUrl && (!pBuffer || cbSize <= 0)) || !ppwzMimeOut)
1075 return E_INVALIDARG;
1078 mimeType = pwzMimeProposed;
1080 /* Try and find the mime type in the registry */
1082 LPWSTR ext = strrchrW(pwzUrl, '.');
1085 if(!RegOpenKeyExW(HKEY_CLASSES_ROOT, ext, 0, 0, &hKey)) {
1086 if(!RegQueryValueExW(hKey, szContentType, NULL, NULL, (LPBYTE)szTmpMime, &dwSize)) {
1087 mimeType = szTmpMime;
1094 if(!mimeType && pBuffer && cbSize > 0)
1095 mimeType = URLMON_IsBinary(pBuffer, cbSize)?szBinaryMime:szTextMime;
1097 TRACE("Using %s\n", debugstr_w(mimeType));
1098 *ppwzMimeOut = CoTaskMemAlloc((lstrlenW(mimeType)+1)*sizeof(WCHAR));
1099 if(!*ppwzMimeOut) return E_OUTOFMEMORY;
1100 lstrcpyW(*ppwzMimeOut, mimeType);
1104 /***********************************************************************
1105 * IsAsyncMoniker (URLMON.@)
1107 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
1113 /***********************************************************************
1114 * RegisterBindStatusCallback (URLMON.@)
1116 * Register a bind status callback.
1119 * pbc [I] Binding context
1120 * pbsc [I] Callback to register
1121 * ppbscPrevious [O] Destination for previous callback
1122 * dwReserved [I] Reserved, must be 0.
1126 * Failure: E_INVALIDARG, if any argument is invalid, or
1127 * E_OUTOFMEMORY if memory allocation fails.
1129 HRESULT WINAPI RegisterBindStatusCallback(
1131 IBindStatusCallback *pbsc,
1132 IBindStatusCallback **ppbscPrevious,
1135 IBindStatusCallback *prev;
1137 TRACE("(%p,%p,%p,%lu)\n", pbc, pbsc, ppbscPrevious, dwReserved);
1139 if (pbc == NULL || pbsc == NULL)
1140 return E_INVALIDARG;
1142 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&prev)))
1144 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1146 *ppbscPrevious = prev;
1148 IBindStatusCallback_Release(prev);
1151 return IBindCtx_RegisterObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown *)pbsc);
1154 /***********************************************************************
1155 * RevokeBindStatusCallback (URLMON.@)
1157 * Unregister a bind status callback.
1159 * pbc [I] Binding context
1160 * pbsc [I] Callback to unregister
1164 * Failure: E_INVALIDARG, if any argument is invalid, or
1165 * E_FAIL if pbsc wasn't registered with pbc.
1167 HRESULT WINAPI RevokeBindStatusCallback(
1169 IBindStatusCallback *pbsc)
1171 IBindStatusCallback *callback;
1172 HRESULT hr = E_FAIL;
1174 TRACE("(%p,%p)\n", pbc, pbsc);
1176 if (pbc == NULL || pbsc == NULL)
1177 return E_INVALIDARG;
1179 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&callback)))
1181 if (callback == pbsc)
1183 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1186 IBindStatusCallback_Release(pbsc);
1192 /***********************************************************************
1193 * ReleaseBindInfo (URLMON.@)
1195 * Release the resources used by the specified BINDINFO structure.
1198 * pbindinfo [I] BINDINFO to release.
1203 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
1205 FIXME("(%p)stub!\n", pbindinfo);
1208 /***********************************************************************
1209 * URLDownloadToFileA (URLMON.@)
1211 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1215 * pCaller [I] controlling IUnknown interface.
1216 * szURL [I] URL of the file to download
1217 * szFileName [I] file name to store the content of the URL
1218 * dwReserved [I] reserved - set to 0
1219 * lpfnCB [I] callback for progress report
1223 * E_OUTOFMEMORY when going out of memory
1225 HRESULT WINAPI URLDownloadToFileA(LPUNKNOWN pCaller,
1229 LPBINDSTATUSCALLBACK lpfnCB)
1231 UNICODE_STRING szURL_w, szFileName_w;
1233 if ((szURL == NULL) || (szFileName == NULL)) {
1234 FIXME("(%p,%s,%s,%08lx,%p) cannot accept NULL strings !\n", pCaller, debugstr_a(szURL), debugstr_a(szFileName), dwReserved, lpfnCB);
1235 return E_INVALIDARG; /* The error code is not specified in this case... */
1238 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w, szURL)) {
1239 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w, szFileName)) {
1240 HRESULT ret = URLDownloadToFileW(pCaller, szURL_w.Buffer, szFileName_w.Buffer, dwReserved, lpfnCB);
1242 RtlFreeUnicodeString(&szURL_w);
1243 RtlFreeUnicodeString(&szFileName_w);
1247 RtlFreeUnicodeString(&szURL_w);
1251 FIXME("(%p,%s,%s,%08lx,%p) could not allocate W strings !\n", pCaller, szURL, szFileName, dwReserved, lpfnCB);
1252 return E_OUTOFMEMORY;
1255 /***********************************************************************
1256 * URLDownloadToFileW (URLMON.@)
1258 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1262 * pCaller [I] controlling IUnknown interface.
1263 * szURL [I] URL of the file to download
1264 * szFileName [I] file name to store the content of the URL
1265 * dwReserved [I] reserved - set to 0
1266 * lpfnCB [I] callback for progress report
1270 * E_OUTOFMEMORY when going out of memory
1272 HRESULT WINAPI URLDownloadToFileW(LPUNKNOWN pCaller,
1276 LPBINDSTATUSCALLBACK lpfnCB)
1278 HINTERNET hinternet, hcon, hreq;
1280 CHAR buffer[0x1000];
1281 DWORD sz, total, written;
1282 DWORD total_size = 0xFFFFFFFF, arg_size = sizeof(total_size);
1283 URL_COMPONENTSW url;
1284 WCHAR host[0x80], path[0x100];
1286 WCHAR wszAppName[]={'u','r','l','m','o','n','.','d','l','l',0};
1288 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1289 TRACE("(%p,%s,%s,%08lx,%p) stub!\n", pCaller, debugstr_w(szURL), debugstr_w(szFileName), dwReserved, lpfnCB);
1291 if ((szURL == NULL) || (szFileName == NULL)) {
1292 FIXME(" cannot accept NULL strings !\n");
1293 return E_INVALIDARG;
1296 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1297 hinternet = InternetOpenW(wszAppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1298 if (hinternet == NULL) {
1299 return E_OUTOFMEMORY;
1302 memset(&url, 0, sizeof(url));
1303 url.dwStructSize = sizeof(url);
1304 url.lpszHostName = host;
1305 url.dwHostNameLength = sizeof(host);
1306 url.lpszUrlPath = path;
1307 url.dwUrlPathLength = sizeof(path);
1309 if (!InternetCrackUrlW(szURL, 0, 0, &url)) {
1310 InternetCloseHandle(hinternet);
1311 return E_OUTOFMEMORY;
1315 if (IBindStatusCallback_OnProgress(lpfnCB, 0, 0, BINDSTATUS_CONNECTING, url.lpszHostName) == E_ABORT) {
1316 InternetCloseHandle(hinternet);
1321 hcon = InternetConnectW(hinternet, url.lpszHostName, url.nPort,
1322 url.lpszUserName, url.lpszPassword,
1323 INTERNET_SERVICE_HTTP, 0, 0);
1325 InternetCloseHandle(hinternet);
1326 return E_OUTOFMEMORY;
1329 hreq = HttpOpenRequestW(hcon, NULL, url.lpszUrlPath, NULL, NULL, NULL, 0, 0);
1331 InternetCloseHandle(hinternet);
1332 InternetCloseHandle(hcon);
1333 return E_OUTOFMEMORY;
1336 if (!HttpSendRequestW(hreq, NULL, 0, NULL, 0)) {
1337 InternetCloseHandle(hinternet);
1338 InternetCloseHandle(hcon);
1339 InternetCloseHandle(hreq);
1340 return E_OUTOFMEMORY;
1343 if (HttpQueryInfoW(hreq, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
1344 &total_size, &arg_size, NULL)) {
1345 TRACE(" total size : %ld\n", total_size);
1348 hfile = CreateFileW(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1349 FILE_ATTRIBUTE_NORMAL, NULL );
1350 if (hfile == INVALID_HANDLE_VALUE) {
1351 return E_ACCESSDENIED;
1355 if (IBindStatusCallback_OnProgress(lpfnCB, 0, total_size != 0xFFFFFFFF ? total_size : 0,
1356 BINDSTATUS_BEGINDOWNLOADDATA, szURL) == E_ABORT) {
1357 InternetCloseHandle(hreq);
1358 InternetCloseHandle(hcon);
1359 InternetCloseHandle(hinternet);
1367 r = InternetReadFile(hreq, buffer, sizeof(buffer), &sz);
1369 InternetCloseHandle(hreq);
1370 InternetCloseHandle(hcon);
1371 InternetCloseHandle(hinternet);
1374 return E_OUTOFMEMORY;
1382 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1383 BINDSTATUS_DOWNLOADINGDATA, szURL) == E_ABORT) {
1384 InternetCloseHandle(hreq);
1385 InternetCloseHandle(hcon);
1386 InternetCloseHandle(hinternet);
1392 if (!WriteFile(hfile, buffer, sz, &written, NULL)) {
1393 InternetCloseHandle(hreq);
1394 InternetCloseHandle(hcon);
1395 InternetCloseHandle(hinternet);
1398 return E_OUTOFMEMORY;
1403 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1404 BINDSTATUS_ENDDOWNLOADDATA, szURL) == E_ABORT) {
1405 InternetCloseHandle(hreq);
1406 InternetCloseHandle(hcon);
1407 InternetCloseHandle(hinternet);
1413 InternetCloseHandle(hreq);
1414 InternetCloseHandle(hcon);
1415 InternetCloseHandle(hinternet);