• C语言实现 IBindStatusCallBack接口, 实现带进度下载


    #include <stdio.h>
    #include <urlmon.h>
    #pragma comment (lib, "urlmon.lib")
    
    HRESULT ( STDMETHODCALLTYPE QueryInterface )( 
        IBindStatusCallback * This,
        /* [in] */ REFIID riid,
        /* [iid_is][out] */ void **ppvObject)
    {
        return E_NOTIMPL;
    }
    
    ULONG ( STDMETHODCALLTYPE AddRef )( 
        IBindStatusCallback * This)
    {
        return E_NOTIMPL;
    }
    
    ULONG ( STDMETHODCALLTYPE Release )( 
        IBindStatusCallback * This)
    {
        return E_NOTIMPL;
    }
    
    HRESULT ( STDMETHODCALLTYPE OnStartBinding )( 
        IBindStatusCallback * This,
        /* [in] */ DWORD dwReserved,
        /* [in] */ IBinding *pib)
    {
        return E_NOTIMPL;
    }
    
    HRESULT ( STDMETHODCALLTYPE GetPriority )( 
        IBindStatusCallback * This,
        /* [out] */ LONG *pnPriority)
    {
        return E_NOTIMPL;
    }
    
    HRESULT ( STDMETHODCALLTYPE OnLowResource )( 
        IBindStatusCallback * This,
        /* [in] */ DWORD reserved)
    {
        return E_NOTIMPL;
    }
    
    HRESULT ( STDMETHODCALLTYPE OnProgress )( 
        IBindStatusCallback * This,
        /* [in] */ ULONG ulProgress,
        /* [in] */ ULONG ulProgressMax,
        /* [in] */ ULONG ulStatusCode,
        /* [in] */ LPCWSTR szStatusText)
    {
        if (ulProgress > 0)
        {   
            printf("Downloaded %d of %d bytes\n",
                ulProgress, ulProgressMax); 
            fflush(stdout);
        }
        return S_OK;
    }
    
    HRESULT ( STDMETHODCALLTYPE OnStopBinding )( 
        IBindStatusCallback * This,
        /* [in] */ HRESULT hresult,
        /* [unique][in] */ LPCWSTR szError)
    {
        return E_NOTIMPL;
    }
    
    HRESULT ( STDMETHODCALLTYPE GetBindInfo )( 
        IBindStatusCallback * This,
        /* [out] */ DWORD *grfBINDF,
        /* [unique][out][in] */ BINDINFO *pbindinfo)
    {
        return E_NOTIMPL;
    }
    
    HRESULT ( STDMETHODCALLTYPE OnDataAvailable )( 
        IBindStatusCallback * This,
        /* [in] */ DWORD grfBSCF,
        /* [in] */ DWORD dwSize,
        /* [in] */ FORMATETC *pformatetc,
        /* [in] */ STGMEDIUM *pstgmed)
    {
        return E_NOTIMPL;
    }
    
    HRESULT ( STDMETHODCALLTYPE OnObjectAvailable )( 
        IBindStatusCallback * This,
        /* [in] */ REFIID riid,
        /* [iid_is][in] */ IUnknown *punk)
    {
        return E_NOTIMPL;
    }
    
    static const IBindStatusCallbackVtbl IBindStatusCallback_Vtbl =
    {
        QueryInterface,
        AddRef,
        Release,
        OnStartBinding,
        GetPriority,
        OnLowResource,
        OnProgress,
        OnStopBinding,
        GetBindInfo,
        OnDataAvailable,
        OnObjectAvailable
    };
    
    int main(int argc, char *argv[])
    {
        HRESULT hr;
        IBindStatusCallback MyCallback;
        MyCallback.lpVtbl = (IBindStatusCallbackVtbl *)&IBindStatusCallback_Vtbl;
        hr = URLDownloadToFile(NULL, "http://www.baidu.com/index.php", "index.php", 0, &MyCallback);
        if (hr != S_OK)
        {
            printf("Error: %X\n", hr);
        }
        return 0;
    }

    女孩不哭(QQ:191035066)@2012-05-02 16:05:03 @ http://www.cnblogs.com/nbsofer

  • 相关阅读:
    Linux c字符串中不可打印字符转换成16进制
    jQuery概述,代码举例及最新版下载
    linux/centos下安装nginx(rpm安装和源码安装)详细步骤
    Session id实现通过Cookie来传输方法及代码参考
    申请Android Map 的API Key(v2)的最新申请方式(SHA1密钥)
    Linux内核中影响tcp三次握手的一些协议配置
    基于DIV+ul+li实现的表格(多示例)
    修改Windows硬盘分区名称
    Linux下c基于openssl生成MD5的函数
    Web前端设计:Html强制不换行<nobr>标签用法代码示例
  • 原文地址:https://www.cnblogs.com/memset/p/2479186.html
Copyright © 2020-2023  润新知