Share via


CBindStatusCallback::StartAsyncDownload

Starts downloading data asynchronously from the specified URL.

HRESULT StartAsyncDownload( 
   T* pT,
   ATL_PDATAAVAILABLE pFunc,
   BSTR bstrURL,
   IUnknown* pUnkContainer = NULL,  
   BOOL bRelative = FALSE  
);

Parameters

  • pT
    [in] A pointer to the object requesting the asynchronous data transfer. The CBindStatusCallback object is templatized on this object's class.

  • pFunc
    [in] A pointer to the function that receives the data being read. The function is a member of your object's class of type T. See Remarks for syntax and an example.

  • bstrURL
    [in] The URL to obtain data from. Can be any valid URL or file name. Cannot be NULL. For example:

    CComBSTR mybstr =_T("http://somesite/data.htm")

  • pUnkContainer
    [in] The IUnknown of the container. NULL by default.

  • bRelative
    [in] A flag indicating whether the URL is relative or absolute. FALSE by default, meaning the URL is absolute.

Return Value

One of the standard HRESULT values.

Remarks

Every time data is available it is sent to the object through OnDataAvailable. OnDataAvailable reads the data and calls the function pointed to by pFunc (for example, to store the data or print it to the screen).

The function pointed to by pFunc is a member of your object's class and has the following syntax:

void Function_Name(

CBindStatusCallback<T>* pbsc,

BYTE* pBytes,

DWORD dwSize

);

In the following example (taken from the ASYNC sample), the function OnData writes the received data into a text box.

Example

void OnData(CBindStatusCallback<CATLAsync>* , BYTE* pBytes, DWORD /*cBytes*/)
{
   ATLTRACE(_T("OnData called\n"));

   m_bstrText.Append((LPCSTR)pBytes);
   if (::IsWindow(m_EditCtrl.m_hWnd))
   {
      USES_CONVERSION;
      _ATLTRY {
         ::SendMessage(m_EditCtrl.m_hWnd, WM_SETTEXT, 0, 
            (LPARAM)(LPCTSTR)COLE2CT((BSTR)m_bstrText));
      }
      _ATLCATCH( e ) {
         e; // unused 
         // COLE2CT threw an exception!
         ::SendMessage(m_EditCtrl.m_hWnd, WM_SETTEXT, 0, 
            (LPARAM)_T("Could not allocate enough memory!!!"));
      }
   }
}

Requirements

Header: atlctl.h

See Also

Reference

CBindStatusCallback Class

CBindStatusCallback::OnDataAvailable

Other Resources

CBindStatusCallback Members