Limit usage of vertex arrays to correct states.
[wine/multimedia.git] / dlls / urlmon / umon.c
blob2ccd56ef3ba93880b1e3ce7a912aabe08cccc84b
1 /*
2 * UrlMon
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
23 #include <stdarg.h>
24 #include <stdio.h>
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winternl.h"
32 #include "winuser.h"
33 #include "objbase.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
36 #include "ole2.h"
37 #include "urlmon.h"
38 #include "wininet.h"
39 #include "urlmon_main.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
43 /* native urlmon.dll uses this key, too */
44 static 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 */
58 HWND hwndCallback;
59 IBindCtx *pBC;
60 HINTERNET hinternet, hconnect, hrequest;
61 } URLMonikerImpl;
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,
123 URLMonikerImpl_Load,
124 URLMonikerImpl_Save,
125 URLMonikerImpl_GetSizeMax,
126 URLMonikerImpl_BindToObject,
127 URLMonikerImpl_BindToStorage,
128 URLMonikerImpl_Reduce,
129 URLMonikerImpl_ComposeWith,
130 URLMonikerImpl_Enum,
131 URLMonikerImpl_IsEqual,
132 URLMonikerImpl_Hash,
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) )
169 return E_INVALIDARG;
171 /* Initialize the return parameter */
172 *ppvObject = 0;
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)
180 *ppvObject = iface;
182 /* Check that we obtained an interface.*/
183 if ((*ppvObject)==0)
184 return E_NOINTERFACE;
186 /* Query Interface always increases the reference count by one when it is successful */
187 URLMonikerImpl_AddRef(iface);
189 return S_OK;
192 /******************************************************************************
193 * URLMoniker_AddRef
194 ******************************************************************************/
195 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
197 ICOM_THIS(URLMonikerImpl,iface);
199 TRACE("(%p)\n",This);
201 return ++(This->ref);
204 /******************************************************************************
205 * URLMoniker_Release
206 ******************************************************************************/
207 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
209 ICOM_THIS(URLMonikerImpl,iface);
211 TRACE("(%p)\n",This);
213 This->ref--;
215 /* destroy the object if there's no more reference on it */
216 if (This->ref==0){
218 URLMonikerImpl_Destroy(This);
220 return 0;
222 return This->ref;
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 FIXME("(%p)->(%p): stub\n",This,pClassID);
235 if (pClassID==NULL)
236 return E_POINTER;
238 return E_NOTIMPL;
241 /******************************************************************************
242 * URLMoniker_IsDirty
243 ******************************************************************************/
244 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface)
246 ICOM_THIS(URLMonikerImpl,iface);
247 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
248 method in the OLE-provided moniker interfaces always return S_FALSE because
249 their internal state never changes. */
251 TRACE("(%p)\n",This);
253 return S_FALSE;
256 /******************************************************************************
257 * URLMoniker_Load
258 ******************************************************************************/
259 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
261 ICOM_THIS(URLMonikerImpl,iface);
263 FIXME("(%p)->(%p): stub\n",This,pStm);
265 return E_NOTIMPL;
268 /******************************************************************************
269 * URLMoniker_Save
270 ******************************************************************************/
271 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
272 IStream* pStm,/* pointer to the stream where the object is to be saved */
273 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
275 ICOM_THIS(URLMonikerImpl,iface);
277 FIXME("(%p)->(%p,%d): stub\n",This,pStm,fClearDirty);
279 return E_NOTIMPL;
283 /******************************************************************************
284 * URLMoniker_GetSizeMax
285 ******************************************************************************/
286 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
287 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
289 ICOM_THIS(URLMonikerImpl,iface);
291 FIXME("(%p)->(%p): stub\n",This,pcbSize);
293 return E_NOTIMPL;
296 /******************************************************************************
297 * URLMoniker_Construct (local function)
298 *******************************************************************************/
299 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszURLName)
301 int sizeStr = strlenW(lpszURLName);
303 TRACE("(%p,%s)\n",This,debugstr_w(lpszURLName));
304 memset(This, 0, sizeof(*This));
306 /* Initialize the virtual fgunction table. */
307 This->lpvtbl1 = &VT_URLMonikerImpl;
308 This->lpvtbl2 = &VTBinding_URLMonikerImpl;
309 This->ref = 0;
311 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1));
313 if (This->URLName==NULL)
314 return E_OUTOFMEMORY;
316 strcpyW(This->URLName,lpszURLName);
318 return S_OK;
323 /******************************************************************************
324 * URLMoniker_Destroy (local function)
325 *******************************************************************************/
326 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* This)
328 TRACE("(%p)\n",This);
330 if (This->URLName!=NULL)
331 HeapFree(GetProcessHeap(),0,This->URLName);
333 HeapFree(GetProcessHeap(),0,This);
335 return S_OK;
338 /******************************************************************************
339 * URLMoniker_BindToObject
340 ******************************************************************************/
341 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
342 IBindCtx* pbc,
343 IMoniker* pmkToLeft,
344 REFIID riid,
345 VOID** ppvResult)
347 ICOM_THIS(URLMonikerImpl,iface);
349 *ppvResult=0;
351 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),
352 ppvResult);
354 return E_NOTIMPL;
357 typedef struct {
358 enum {OnProgress, OnDataAvailable} callback;
359 } URLMON_CallbackData;
362 #if 0
363 static LRESULT CALLBACK URLMON_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
365 return DefWindowProcA(hwnd, msg, wparam, lparam);
368 static void PostOnProgress(URLMonikerImpl *This, UINT progress, UINT maxprogress, DWORD status, LPCWSTR *str)
372 static void CALLBACK URLMON_InternetCallback(HINTERNET hinet, /*DWORD_PTR*/ DWORD context, DWORD status,
373 void *status_info, DWORD status_info_len)
375 URLMonikerImpl *This = (URLMonikerImpl *)context;
376 TRACE("handle %p this %p status %08lx\n", hinet, This, status);
378 if(This->filesize == -1) {
379 switch(status) {
380 case INTERNET_STATUS_RESOLVING_NAME:
381 PostOnProgess(This, 0, 0, BINDSTATUS_FINDINGRESOURCE, status_info);
382 break;
383 case INTERNET_STATUS_CONNECTING_TO_SERVER:
384 PostOnProgress(This, 0, 0, BINDSTATUS_CONNECTING, NULL);
385 break;
386 case INTERNET_STATUS_SENDING_REQUEST:
387 PostOnProgress(This, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
388 break;
389 case INTERNET_REQUEST_COMPLETE:
391 DWORD len, lensz = sizeof(len);
393 HttpQueryInfoW(hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
394 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
395 This->filesize = len;
396 break;
401 return;
403 #endif
404 /******************************************************************************
405 * URLMoniker_BindToStorage
406 ******************************************************************************/
407 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
408 IBindCtx* pbc,
409 IMoniker* pmkToLeft,
410 REFIID riid,
411 VOID** ppvObject)
413 ICOM_THIS(URLMonikerImpl,iface);
414 HRESULT hres;
415 IBindStatusCallback *pbscb;
416 BINDINFO bi;
417 DWORD bindf;
419 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),ppvObject);
420 if(pmkToLeft) {
421 FIXME("pmkToLeft != NULL\n");
422 return E_NOTIMPL;
424 if(!IsEqualIID(&IID_IStream, riid)) {
425 FIXME("unsupported iid\n");
426 return E_NOTIMPL;
429 /* FIXME This is a bad hack (tm). We should clearly download to a temporary file.
430 We also need to implement IStream ourselves so that IStream_Read can return
431 E_PENDING */
433 hres = CreateStreamOnHGlobal(0, TRUE, (IStream**)ppvObject);
436 if(SUCCEEDED(hres)) {
437 TRACE("Created dummy stream...\n");
439 hres = IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown**)&pbscb);
440 if(SUCCEEDED(hres)) {
441 TRACE("Got IBindStatusCallback...\n");
443 memset(&bi, 0, sizeof(bi));
444 bi.cbSize = sizeof(bi);
445 bindf = 0;
446 hres = IBindStatusCallback_GetBindInfo(pbscb, &bindf, &bi);
447 if(SUCCEEDED(hres)) {
448 URL_COMPONENTSW url;
449 WCHAR *host, *path;
450 DWORD len, lensz = sizeof(len), total_read = 0;
451 LARGE_INTEGER last_read_pos;
452 FORMATETC fmt;
453 STGMEDIUM stg;
455 TRACE("got bindinfo. bindf = %08lx extrainfo = %s bindinfof = %08lx bindverb = %08lx iid %s\n",
456 bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
457 hres = IBindStatusCallback_OnStartBinding(pbscb, 0, (IBinding*)&This->lpvtbl2);
458 TRACE("OnStartBinding rets %08lx\n", hres);
460 #if 0
461 if(!registered_wndclass) {
462 WNDCLASSA urlmon_wndclass = {0, URLMON_WndProc,0, 0, URLMON_hInstance, 0, 0, 0, NULL, "URLMON_Callback_Window_Class"};
463 RegisterClassA(&urlmon_wndclass);
464 registered_wndclass = TRUE;
467 This->hwndCallback = CreateWindowA("URLMON_Callback_Window_Class", NULL, 0, 0, 0, 0, 0, 0, 0,
468 URLMON_hInstance, NULL);
470 #endif
471 memset(&url, 0, sizeof(url));
472 url.dwStructSize = sizeof(url);
473 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = 1;
474 InternetCrackUrlW(This->URLName, 0, 0, &url);
475 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
476 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
477 host[url.dwHostNameLength] = '\0';
478 path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
479 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
480 path[url.dwUrlPathLength] = '\0';
482 This->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0 /*INTERNET_FLAG_ASYNC*/);
483 /* InternetSetStatusCallback(This->hinternet, URLMON_InternetCallback);*/
485 This->hconnect = InternetConnectW(This->hinternet, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
486 INTERNET_SERVICE_HTTP, 0, (DWORD)This);
487 This->hrequest = HttpOpenRequestW(This->hconnect, NULL, path, NULL, NULL, NULL, 0, (DWORD)This);
489 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, 0x22, NULL);
490 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
491 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
492 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
493 hres = E_OUTOFMEMORY; /* FIXME */
494 if(HttpSendRequestW(This->hrequest, NULL, 0, NULL, 0)) {
496 len = 0;
497 HttpQueryInfoW(This->hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
499 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
501 last_read_pos.s.LowPart = last_read_pos.s.HighPart = 0;
502 fmt.cfFormat = 0;
503 fmt.ptd = NULL;
504 fmt.dwAspect = 0;
505 fmt.lindex = -1;
506 fmt.tymed = TYMED_ISTREAM;
507 stg.tymed = TYMED_ISTREAM;
508 stg.u.pstm = *(IStream**)ppvObject;
509 stg.pUnkForRelease = NULL;
511 while(1) {
512 char buf[4096];
513 DWORD bufread;
514 DWORD written;
515 if(InternetReadFile(This->hrequest, buf, sizeof(buf), &bufread)) {
516 TRACE("read %ld bytes %s...\n", bufread, debugstr_an(buf, 10));
517 if(bufread == 0) break;
518 IStream_Write(*(IStream**)ppvObject, buf, bufread, &written);
519 total_read += bufread;
520 IStream_Seek(*(IStream**)ppvObject, last_read_pos, STREAM_SEEK_SET, NULL);
521 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, (total_read == bufread) ?
522 BINDSTATUS_BEGINDOWNLOADDATA :
523 BINDSTATUS_DOWNLOADINGDATA, NULL);
524 hres = IBindStatusCallback_OnDataAvailable(pbscb,
525 (total_read == bufread) ? BSCF_FIRSTDATANOTIFICATION :
526 BSCF_INTERMEDIATEDATANOTIFICATION,
527 total_read, &fmt, &stg);
528 last_read_pos.s.LowPart += bufread; /* FIXME */
529 } else
530 break;
532 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, BINDSTATUS_ENDDOWNLOADDATA, NULL);
533 hres = IBindStatusCallback_OnDataAvailable(pbscb, BSCF_LASTDATANOTIFICATION, total_read, &fmt, &stg);
534 TRACE("OnDataAvail rets %08lx\n", hres);
535 hres = IBindStatusCallback_OnStopBinding(pbscb, S_OK, NULL);
536 TRACE("OnStop rets %08lx\n", hres);
537 hres = S_OK;
539 InternetCloseHandle(This->hrequest);
540 InternetCloseHandle(This->hconnect);
541 InternetCloseHandle(This->hinternet);
545 return hres;
548 /******************************************************************************
549 * URLMoniker_Reduce
550 ******************************************************************************/
551 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
552 IBindCtx* pbc,
553 DWORD dwReduceHowFar,
554 IMoniker** ppmkToLeft,
555 IMoniker** ppmkReduced)
557 ICOM_THIS(URLMonikerImpl,iface);
558 FIXME("(%p)->(%p,%ld,%p,%p): stub\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
560 return E_NOTIMPL;
563 /******************************************************************************
564 * URLMoniker_ComposeWith
565 ******************************************************************************/
566 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
567 IMoniker* pmkRight,
568 BOOL fOnlyIfNotGeneric,
569 IMoniker** ppmkComposite)
571 ICOM_THIS(URLMonikerImpl,iface);
572 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
574 return E_NOTIMPL;
577 /******************************************************************************
578 * URLMoniker_Enum
579 ******************************************************************************/
580 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
582 ICOM_THIS(URLMonikerImpl,iface);
583 FIXME("(%p)->(%d,%p): stub\n",This,fForward,ppenumMoniker);
585 return E_NOTIMPL;
588 /******************************************************************************
589 * URLMoniker_IsEqual
590 ******************************************************************************/
591 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
593 ICOM_THIS(URLMonikerImpl,iface);
594 FIXME("(%p)->(%p): stub\n",This,pmkOtherMoniker);
596 return E_NOTIMPL;
600 /******************************************************************************
601 * URLMoniker_Hash
602 ******************************************************************************/
603 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
605 ICOM_THIS(URLMonikerImpl,iface);
606 FIXME("(%p)->(%p): stub\n",This,pdwHash);
608 return E_NOTIMPL;
611 /******************************************************************************
612 * URLMoniker_IsRunning
613 ******************************************************************************/
614 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
615 IBindCtx* pbc,
616 IMoniker* pmkToLeft,
617 IMoniker* pmkNewlyRunning)
619 ICOM_THIS(URLMonikerImpl,iface);
620 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
622 return E_NOTIMPL;
625 /******************************************************************************
626 * URLMoniker_GetTimeOfLastChange
627 ******************************************************************************/
628 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
629 IBindCtx* pbc,
630 IMoniker* pmkToLeft,
631 FILETIME* pFileTime)
633 ICOM_THIS(URLMonikerImpl,iface);
634 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
636 return E_NOTIMPL;
639 /******************************************************************************
640 * URLMoniker_Inverse
641 ******************************************************************************/
642 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
644 ICOM_THIS(URLMonikerImpl,iface);
645 FIXME("(%p)->(%p): stub\n",This,ppmk);
647 return E_NOTIMPL;
650 /******************************************************************************
651 * URLMoniker_CommonPrefixWith
652 ******************************************************************************/
653 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
655 ICOM_THIS(URLMonikerImpl,iface);
656 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
658 return E_NOTIMPL;
661 /******************************************************************************
662 * URLMoniker_RelativePathTo
663 ******************************************************************************/
664 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
666 ICOM_THIS(URLMonikerImpl,iface);
667 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
669 return E_NOTIMPL;
672 /******************************************************************************
673 * URLMoniker_GetDisplayName
674 ******************************************************************************/
675 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
676 IBindCtx* pbc,
677 IMoniker* pmkToLeft,
678 LPOLESTR *ppszDisplayName)
680 ICOM_THIS(URLMonikerImpl,iface);
681 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,ppszDisplayName);
683 return E_NOTIMPL;
686 /******************************************************************************
687 * URLMoniker_ParseDisplayName
688 ******************************************************************************/
689 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
690 IBindCtx* pbc,
691 IMoniker* pmkToLeft,
692 LPOLESTR pszDisplayName,
693 ULONG* pchEaten,
694 IMoniker** ppmkOut)
696 ICOM_THIS(URLMonikerImpl,iface);
697 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
699 return E_NOTIMPL;
702 /******************************************************************************
703 * URLMoniker_IsSystemMoniker
704 ******************************************************************************/
705 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
707 ICOM_THIS(URLMonikerImpl,iface);
708 FIXME("(%p)->(%p)\n",This,pwdMksys);
710 return E_NOTIMPL;
713 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject)
715 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
717 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
719 /* Perform a sanity check on the parameters.*/
720 if ( (This==0) || (ppvObject==0) )
721 return E_INVALIDARG;
723 /* Initialize the return parameter */
724 *ppvObject = 0;
726 /* Compare the riid with the interface IDs implemented by this object.*/
727 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid))
728 *ppvObject = iface;
730 /* Check that we obtained an interface.*/
731 if ((*ppvObject)==0)
732 return E_NOINTERFACE;
734 /* Query Interface always increases the reference count by one when it is successful */
735 URLMonikerImpl_IBinding_AddRef(iface);
737 return S_OK;
741 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface)
743 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
744 TRACE("(%p)\n",This);
746 return URLMonikerImpl_AddRef((IMoniker*)This);
749 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface)
751 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
752 TRACE("(%p)\n",This);
754 return URLMonikerImpl_Release((IMoniker*)This);
757 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface)
759 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
760 FIXME("(%p): stub\n", This);
762 return E_NOTIMPL;
765 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
767 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
768 FIXME("(%p)->(%s, %p, %p, %p): stub\n", This, debugstr_guid(pclsidProtocol), pdwResult, pszResult, pdwReserved);
770 return E_NOTIMPL;
773 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority)
775 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
776 FIXME("(%p)->(%p): stub\n", This, pnPriority);
778 return E_NOTIMPL;
781 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface)
783 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
784 FIXME("(%p): stub\n", This);
786 return E_NOTIMPL;
789 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority)
791 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
792 FIXME("(%p)->(%ld): stub\n", This, nPriority);
794 return E_NOTIMPL;
797 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface)
799 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
800 FIXME("(%p): stub\n", This);
802 return E_NOTIMPL;
805 /***********************************************************************
806 * CreateAsyncBindCtxEx (URLMON.@)
808 * Create an asynchronous bind context.
810 * FIXME
811 * Not implemented.
813 HRESULT WINAPI CreateAsyncBindCtxEx(IBindCtx *ibind, DWORD options,
814 IBindStatusCallback *callback, IEnumFORMATETC *format, IBindCtx** pbind,
815 DWORD reserved)
817 FIXME("stub, returns failure\n");
818 return E_INVALIDARG;
822 /***********************************************************************
823 * CreateURLMoniker (URLMON.@)
825 * Create a url moniker.
827 * PARAMS
828 * pmkContext [I] Context
829 * szURL [I] Url to create the moniker for
830 * ppmk [O] Destination for created moniker.
832 * RETURNS
833 * Success: S_OK. ppmk contains the created IMoniker object.
834 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
835 * E_OUTOFMEMORY if memory allocation fails.
837 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
839 URLMonikerImpl *obj;
840 HRESULT hres;
841 IID iid = IID_IMoniker;
843 TRACE("(%p, %s, %p)\n", pmkContext, debugstr_w(szURL), ppmk);
845 if (NULL != pmkContext)
846 FIXME("Non-null pmkContext not implemented\n");
848 if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj))))
849 return E_OUTOFMEMORY;
851 hres = URLMonikerImpl_Construct(obj, szURL);
852 if(SUCCEEDED(hres))
853 hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &iid, (void**)ppmk);
854 else
855 HeapFree(GetProcessHeap(), 0, obj);
856 return hres;
860 /***********************************************************************
861 * CoInternetGetSession (URLMON.@)
863 * Create a new internet session and return an IInternetSession interface
864 * representing it.
866 * PARAMS
867 * dwSessionMode [I] Mode for the internet session
868 * ppIInternetSession [O] Destination for creates IInternetSession object
869 * dwReserved [I] Reserved, must be 0.
871 * RETURNS
872 * Success: S_OK. ppIInternetSession contains the IInternetSession interface.
873 * Failure: E_INVALIDARG, if any argument is invalid, or
874 * E_OUTOFMEMORY if memory allocation fails.
876 HRESULT WINAPI CoInternetGetSession(DWORD dwSessionMode, /*IInternetSession*/void **ppIInternetSession, DWORD dwReserved)
878 FIXME("(%ld, %p, %ld): stub\n", dwSessionMode, ppIInternetSession, dwReserved);
880 if(dwSessionMode) {
881 ERR("dwSessionMode: %ld, must be zero\n", dwSessionMode);
884 if(dwReserved) {
885 ERR("dwReserved: %ld, must be zero\n", dwReserved);
888 *ppIInternetSession=NULL;
889 return E_OUTOFMEMORY;
892 /***********************************************************************
893 * CoInternetQueryInfo (URLMON.@)
895 * Retrieves information relevant to a specified URL
897 * RETURNS
898 * S_OK success
899 * S_FALSE buffer too small
900 * INET_E_QUERYOPTIONUNKNOWN invalid option
903 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
904 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD * pcbBuffer,
905 DWORD dwReserved)
907 FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl),
908 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
909 return S_OK;
912 /***********************************************************************
913 * FindMimeFromData (URLMON.@)
915 * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
918 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
919 DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
920 LPWSTR* ppwzMimeOut, DWORD dwReserved)
922 FIXME("stub\n");
923 return E_OUTOFMEMORY;
926 /***********************************************************************
927 * RegisterBindStatusCallback (URLMON.@)
929 * Register a bind status callback.
931 * PARAMS
932 * pbc [I] Binding context
933 * pbsc [I] Callback to register
934 * ppbscPrevious [O] Destination for previous callback
935 * dwReserved [I] Reserved, must be 0.
937 * RETURNS
938 * Success: S_OK.
939 * Failure: E_INVALIDARG, if any argument is invalid, or
940 * E_OUTOFMEMORY if memory allocation fails.
942 HRESULT WINAPI RegisterBindStatusCallback(
943 IBindCtx *pbc,
944 IBindStatusCallback *pbsc,
945 IBindStatusCallback **ppbscPrevious,
946 DWORD dwReserved)
948 IBindStatusCallback *prev;
950 TRACE("(%p,%p,%p,%lu)\n", pbc, pbsc, ppbscPrevious, dwReserved);
952 if (pbc == NULL || pbsc == NULL)
953 return E_INVALIDARG;
955 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown **)&prev)))
957 IBindCtx_RevokeObjectParam(pbc, BSCBHolder);
958 if (ppbscPrevious)
959 *ppbscPrevious = prev;
960 else
961 IBindStatusCallback_Release(prev);
964 return IBindCtx_RegisterObjectParam(pbc, BSCBHolder, (IUnknown *)pbsc);
967 /***********************************************************************
968 * RevokeBindStatusCallback (URLMON.@)
970 * Unregister a bind status callback.
972 * pbc [I] Binding context
973 * pbsc [I] Callback to unregister
975 * RETURNS
976 * Success: S_OK.
977 * Failure: E_INVALIDARG, if any argument is invalid, or
978 * E_FAIL if pbsc wasn't registered with pbc.
980 HRESULT WINAPI RevokeBindStatusCallback(
981 IBindCtx *pbc,
982 IBindStatusCallback *pbsc)
984 IBindStatusCallback *callback;
985 HRESULT hr = E_FAIL;
987 TRACE("(%p,%p)\n", pbc, pbsc);
989 if (pbc == NULL || pbsc == NULL)
990 return E_INVALIDARG;
992 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown **)&callback)))
994 if (callback == pbsc)
996 IBindCtx_RevokeObjectParam(pbc, BSCBHolder);
997 hr = S_OK;
999 IBindStatusCallback_Release(pbsc);
1002 return hr;
1005 /***********************************************************************
1006 * ReleaseBindInfo (URLMON.@)
1008 * Release the resources used by the specified BINDINFO structure.
1010 * PARAMS
1011 * pbindinfo [I] BINDINFO to release.
1013 * RETURNS
1014 * Nothing.
1016 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
1018 FIXME("(%p)stub!\n", pbindinfo);
1021 /***********************************************************************
1022 * URLDownloadToFileA (URLMON.@)
1024 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1025 * report progress.
1027 * PARAMS
1028 * pCaller [I] controlling IUnknown interface.
1029 * szURL [I] URL of the file to download
1030 * szFileName [I] file name to store the content of the URL
1031 * dwReserved [I] reserved - set to 0
1032 * lpfnCB [I] callback for progress report
1034 * RETURNS
1035 * S_OK on success
1036 * E_OUTOFMEMORY when going out of memory
1038 HRESULT WINAPI URLDownloadToFileA(LPUNKNOWN pCaller,
1039 LPCSTR szURL,
1040 LPCSTR szFileName,
1041 DWORD dwReserved,
1042 LPBINDSTATUSCALLBACK lpfnCB)
1044 UNICODE_STRING szURL_w, szFileName_w;
1046 if ((szURL == NULL) || (szFileName == NULL)) {
1047 FIXME("(%p,%s,%s,%08lx,%p) cannot accept NULL strings !\n", pCaller, debugstr_a(szURL), debugstr_a(szFileName), dwReserved, lpfnCB);
1048 return E_INVALIDARG; /* The error code is not specified in this case... */
1051 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w, szURL)) {
1052 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w, szFileName)) {
1053 HRESULT ret = URLDownloadToFileW(pCaller, szURL_w.Buffer, szFileName_w.Buffer, dwReserved, lpfnCB);
1055 RtlFreeUnicodeString(&szURL_w);
1056 RtlFreeUnicodeString(&szFileName_w);
1058 return ret;
1059 } else {
1060 RtlFreeUnicodeString(&szURL_w);
1064 FIXME("(%p,%s,%s,%08lx,%p) could not allocate W strings !\n", pCaller, szURL, szFileName, dwReserved, lpfnCB);
1065 return E_OUTOFMEMORY;
1068 /***********************************************************************
1069 * URLDownloadToFileW (URLMON.@)
1071 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1072 * report progress.
1074 * PARAMS
1075 * pCaller [I] controlling IUnknown interface.
1076 * szURL [I] URL of the file to download
1077 * szFileName [I] file name to store the content of the URL
1078 * dwReserved [I] reserved - set to 0
1079 * lpfnCB [I] callback for progress report
1081 * RETURNS
1082 * S_OK on success
1083 * E_OUTOFMEMORY when going out of memory
1085 HRESULT WINAPI URLDownloadToFileW(LPUNKNOWN pCaller,
1086 LPCWSTR szURL,
1087 LPCWSTR szFileName,
1088 DWORD dwReserved,
1089 LPBINDSTATUSCALLBACK lpfnCB)
1091 HINTERNET hinternet, hcon, hreq;
1092 BOOL r;
1093 CHAR buffer[0x1000];
1094 DWORD sz, total, written;
1095 DWORD total_size = 0xFFFFFFFF, arg_size = sizeof(total_size);
1096 URL_COMPONENTSW url;
1097 WCHAR host[0x80], path[0x100];
1098 HANDLE hfile;
1099 WCHAR wszAppName[]={'u','r','l','m','o','n','.','d','l','l',0};
1101 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1102 TRACE("(%p,%s,%s,%08lx,%p) stub!\n", pCaller, debugstr_w(szURL), debugstr_w(szFileName), dwReserved, lpfnCB);
1104 if ((szURL == NULL) || (szFileName == NULL)) {
1105 FIXME(" cannot accept NULL strings !\n");
1106 return E_INVALIDARG;
1109 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1110 hinternet = InternetOpenW(wszAppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1111 if (hinternet == NULL) {
1112 return E_OUTOFMEMORY;
1115 memset(&url, 0, sizeof(url));
1116 url.dwStructSize = sizeof(url);
1117 url.lpszHostName = host;
1118 url.dwHostNameLength = sizeof(host);
1119 url.lpszUrlPath = path;
1120 url.dwUrlPathLength = sizeof(path);
1122 if (!InternetCrackUrlW(szURL, 0, 0, &url)) {
1123 InternetCloseHandle(hinternet);
1124 return E_OUTOFMEMORY;
1127 if (lpfnCB) {
1128 if (IBindStatusCallback_OnProgress(lpfnCB, 0, 0, BINDSTATUS_CONNECTING, url.lpszHostName) == E_ABORT) {
1129 InternetCloseHandle(hinternet);
1130 return S_OK;
1134 hcon = InternetConnectW(hinternet, url.lpszHostName, url.nPort,
1135 url.lpszUserName, url.lpszPassword,
1136 INTERNET_SERVICE_HTTP, 0, 0);
1137 if (!hcon) {
1138 InternetCloseHandle(hinternet);
1139 return E_OUTOFMEMORY;
1142 hreq = HttpOpenRequestW(hcon, NULL, url.lpszUrlPath, NULL, NULL, NULL, 0, 0);
1143 if (!hreq) {
1144 InternetCloseHandle(hinternet);
1145 InternetCloseHandle(hcon);
1146 return E_OUTOFMEMORY;
1149 if (!HttpSendRequestW(hreq, NULL, 0, NULL, 0)) {
1150 InternetCloseHandle(hinternet);
1151 InternetCloseHandle(hcon);
1152 InternetCloseHandle(hreq);
1153 return E_OUTOFMEMORY;
1156 if (HttpQueryInfoW(hreq, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
1157 &total_size, &arg_size, NULL)) {
1158 TRACE(" total size : %ld\n", total_size);
1161 hfile = CreateFileW(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1162 FILE_ATTRIBUTE_NORMAL, NULL );
1163 if (hfile == INVALID_HANDLE_VALUE) {
1164 return E_ACCESSDENIED;
1167 if (lpfnCB) {
1168 if (IBindStatusCallback_OnProgress(lpfnCB, 0, total_size != 0xFFFFFFFF ? total_size : 0,
1169 BINDSTATUS_BEGINDOWNLOADDATA, szURL) == E_ABORT) {
1170 InternetCloseHandle(hreq);
1171 InternetCloseHandle(hcon);
1172 InternetCloseHandle(hinternet);
1173 CloseHandle(hfile);
1174 return S_OK;
1178 total = 0;
1179 while (1) {
1180 r = InternetReadFile(hreq, buffer, sizeof(buffer), &sz);
1181 if (!r) {
1182 InternetCloseHandle(hreq);
1183 InternetCloseHandle(hcon);
1184 InternetCloseHandle(hinternet);
1186 CloseHandle(hfile);
1187 return E_OUTOFMEMORY;
1189 if (!sz)
1190 break;
1192 total += sz;
1194 if (lpfnCB) {
1195 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1196 BINDSTATUS_DOWNLOADINGDATA, szURL) == E_ABORT) {
1197 InternetCloseHandle(hreq);
1198 InternetCloseHandle(hcon);
1199 InternetCloseHandle(hinternet);
1200 CloseHandle(hfile);
1201 return S_OK;
1205 if (!WriteFile(hfile, buffer, sz, &written, NULL)) {
1206 InternetCloseHandle(hreq);
1207 InternetCloseHandle(hcon);
1208 InternetCloseHandle(hinternet);
1210 CloseHandle(hfile);
1211 return E_OUTOFMEMORY;
1215 if (lpfnCB) {
1216 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1217 BINDSTATUS_ENDDOWNLOADDATA, szURL) == E_ABORT) {
1218 InternetCloseHandle(hreq);
1219 InternetCloseHandle(hcon);
1220 InternetCloseHandle(hinternet);
1221 CloseHandle(hfile);
1222 return S_OK;
1226 InternetCloseHandle(hreq);
1227 InternetCloseHandle(hcon);
1228 InternetCloseHandle(hinternet);
1230 CloseHandle(hfile);
1232 return S_OK;