zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    2020年JVM面试题记录
    Java对象创建过程
    Java内存模型
    JavaMail读取邮件,如何过滤需要的邮件
    Java Mail 邮件 定时收件
    Java很简单的文件上传(transferTo方式)
    Java架构师之必须掌握的10个开源工具
    Java互联网安全项目架构平台设计
    Java互联网安全项目架构设计第一篇
    Apache POI 4.0.1版本 Excel导出数据案例(兼容 xls 和 xlsx)(六)
  • 原文地址:https://www.cnblogs.com/memset/p/2479186.html
Copyright © 2011-2022 走看看