Using IMoniker to download files?
Hi,
I'm looking for better alternatives to URLDownloadToFile/URLOpenStream. From
what I understand, these APIs are synchronized APIs. They won't return
before the download finishes. They won't even if I specify the
BINDF_ASYNCHRONOUS flag in IBindStatusCallback::GetBindInfo.
As I've been searching, I found the following implementation segment, that
appeared to be asynchronous.
IMoniker* pMoniker;
IBindCtx* pBindCtx;
IBindStatusCallback *pOldCB;
IStream* pStreamDummy = NULL;
hr = CreateURLMoniker(0, szwUrl, &pMoniker);
hr = CreateAsyncBindCtx(0, pIECallback, 0, &pBindCtx);
hr = RegisterBindStatusCallback (pBindCtx, pIECallback, &pOldCB, 0);
hr = pMoniker->BindToStorage(pBindCtx, 0, IID_IStream,
(void**)&pStreamDummy);
Sleep(5000); // just to clarify the problem
*pIECallback implements IBindStatusCallback. I'm sure it's correct as I've
been testing it using URLOpenStream. It reports progress and writes data
correctly.
However, the above code piece doesn't initiate a downloading process. The
first 3 "hrs" are all S_OK. And the last "hr" is 0x000401e8. I checked the
source code, and found no defined macro for this error code. pStreamDummy is
still NULL after this call.
Any ideas on how to get it work?
Best regards,
--
He Shiming
date: Tue, 26 Jul 2005 11:16:27 +0800
author: He Shiming mailbill(NOSPAM)@21cn.com.nospam