Re: Download directly to memory
Hi Igor,
Thanks for the reply.
template <class T>
class ATL_NO_VTABLE CBindStatusCB :
public CComObjectRootEx<T::_ThreadModel::ThreadModelNoCS>,
public IBindStatusCallback
{
STDMETHOD(GetBindInfo)(DWORD *pgrfBINDF, BINDINFO *pbindInfo)
{
if((pbindInfo==NULL) || (pbindInfo->cbSize==0) ||
(pgrfBINDF==NULL))
{
return E_INVALIDARG;
}
*pgrfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE |
BINDF_GETNEWESTVERSION | BINDF_NOWRITECACHE|
BINDF_PRAGMA_NO_CACHE
| BINDF_FROMURLMON
| BINDF_PULLDATA;
ULONG cbSize = pbindInfo->cbSize; // remember incoming
cbSize
memset(pbindInfo, 0, cbSize);
pbindInfo->cbSize = cbSize;
pbindInfo->dwBindVerb = BINDVERB_GET; // set verb
return(S_OK);
}
HRESULT _StartAsyncDownload(BSTR bstrURL, IBindHost *spBindHost, BOOL
bRelative)
{
HRESULT hr = S_OK;
IStream *spStream = NULL;
m_dwTotalRead = 0;
m_dwAvailableToRead = 0;
m_dwProgress = 0;
m_dwProgressMax = 0;
TRACE4("bstrURL(%S) spBindHost(%x) bRelative(%u)", bstrURL,
spBindHost, bRelative);
if(spBindHost != NULL)
{
hr = CreateAsyncBindCtx(0,
static_cast<IBindStatusCallback*>(this),
NULL,
&m_spBindCtx);
if(SUCCEEDED(hr))
{
if(bRelative == TRUE)
{
hr = spBindHost->CreateMoniker(bstrURL,
m_spBindCtx, &m_spMoniker, 0);
}
else
{
hr = CreateURLMoniker(NULL, bstrURL, &m_spMoniker);
}
if(SUCCEEDED(hr))
{
hr = spBindHost->MonikerBindToStorage(m_spMoniker,
m_spBindCtx,
static_cast<IBindStatusCallback*>(this),
IID_IStream,
(void**)&spStream);
if(FAILED(hr))
{
TRACE1("MonikerBindToStorage failed");
}
}
else
{
TRACE1("CreateURLMoniker failed");
}
}
else
{
TRACE1("CreateAsyncBindCtx failed");
}
}
// Other methods
OnDataAvailable(...) { < I receive data here> }
OnProgress(...) { < I receive progress events here>}
};
The is another of my classes that I use to download asynchronously,
however, this DOES download to internet cache before giving me data in
OnDataAvailable().
I get the spBindHost in the following manner from container:
CComPtr<IServiceProvider> spServiceProvider;
hr =
m_spClientSite->QueryInterface(IID_IServiceProvider, (void
**)&spServiceProvider);
if(spServiceProvider != NULL)
{
hr = spServiceProvider->QueryService(SID_IBindHost,
IID_IBindHost,
(void**)&m_spBindHost);
TRACE2("m_spBindHost(%x)", m_spBindHost);
}
else
{
TRACE1("spServiceProvider is set to NULL");
}
Any ideas in what is going wrong with this?