Need help with IBindStatusCallback

This is a discussion on Need help with IBindStatusCallback within the Windows Programming forums, part of the Platform Specific Boards category; Hey, I'm having trouble trying to figure out how to use the IBindStatusCallback object. I've looked into this on msdn ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    Unhappy Need help with IBindStatusCallback

    Hey, I'm having trouble trying to figure out how to use the IBindStatusCallback object. I've looked into this on msdn but it doesn't really make sense to me. Theres so much stuff that I have to read like Url Monikers and com objects. All I want to do is setup an IBindStatusCallback object, and the only function I want to use is OnProgress. I need this so that I can find out the progress of a download while using the URLDownloadToFile function. Can someone please help me with this and maybe even show me some source code?

  2. #2
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    lol, I've already looked at that.
    Ok, I figured it out just look at the post below.
    Last edited by pinkcheese; 03-31-2002 at 10:14 PM.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    Hey, I actually got it to work. Could you tell me how I can make it so that my program doesn't lock up while it is downloading though. The progress which is just a static text shows the size in bytes of the program when it is finished downloading so I know its working. Here is the code I am using for the IBindStatusCallback.

    Code:
    class CCallback : public IBindStatusCallback 
    { 
    public: 
    CCallback(); 
    ~CCallback(); 
    
    // Pointer to the main dialog. 
    HWND hwnd;
    
    STDMETHOD(OnStartBinding)( 
    /* [in] */ DWORD dwReserved, 
    /* [in] */ IBinding __RPC_FAR *pib) 
    { return E_NOTIMPL; } 
    
    STDMETHOD(GetPriority)( 
    /* [out] */ LONG __RPC_FAR *pnPriority) 
    { return E_NOTIMPL; } 
    
    STDMETHOD(OnLowResource)( 
    /* [in] */ DWORD reserved) 
    { return E_NOTIMPL; } 
    
    STDMETHOD(OnProgress)( 
    /* [in] */ ULONG ulProgress, 
    /* [in] */ ULONG ulProgressMax, 
    /* [in] */ ULONG ulStatusCode, 
    /* [in] */ LPCWSTR wszStatusText); 
    
    STDMETHOD(OnStopBinding)( 
    /* [in] */ HRESULT hresult, 
    /* [unique][in] */ LPCWSTR szError) 
    { return E_NOTIMPL; } 
    
    STDMETHOD(GetBindInfo)( 
    /* [out] */ DWORD __RPC_FAR *grfBINDF, 
    /* [unique][out][in] */ BINDINFO __RPC_FAR *pbindinfo) 
    { return E_NOTIMPL; } 
    
    STDMETHOD(OnDataAvailable)( 
    /* [in] */ DWORD grfBSCF, 
    /* [in] */ DWORD dwSize, 
    /* [in] */ FORMATETC __RPC_FAR *pformatetc, 
    /* [in] */ STGMEDIUM __RPC_FAR *pstgmed) 
    { return E_NOTIMPL; } 
    
    STDMETHOD(OnObjectAvailable)( 
    /* [in] */ REFIID riid, 
    /* [iid_is][in] */ IUnknown __RPC_FAR *punk) 
    { return E_NOTIMPL; } 
    
    STDMETHOD_(ULONG,AddRef)() 
    { return 0; } 
    
    STDMETHOD_(ULONG,Release)() 
    { return 0; } 
    
    STDMETHOD(QueryInterface)( 
    /* [in] */ REFIID riid, 
    /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject) 
    { return E_NOTIMPL; } 
    }; 
    
    CCallback::CCallback()
    { 
    } 
    
    CCallback::~CCallback() 
    { 
    } 
    
    HRESULT CCallback::OnProgress ( ULONG ulProgress, ULONG ulProgressMax, 
    ULONG ulStatusCode, LPCWSTR wszStatusText ) 
    {
    	SetDlgItemInt(hwnd, IDC_HOWFAR, (UINT)ulProgress, FALSE);
    	return S_OK; 
    }
    And then I make the object:
    CCallback callback;
    callback.hwnd = hwnd; // hwnd is the window handle to my main

    And then I call the function:
    URLDownloadToFile(NULL, buffer, szFileName, 0, &callback);

    Now all I have to do is get tidy it up a little and make it not lock up while downloading.

    PS. Sorry about all the messy code

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21