当前位置:七道奇文章资讯编程技术VC/C++编程
日期:2011-03-22 13:55:00  来源:本站整理

<b>一段可以下载文件的源代码</b>[VC/C++编程]

赞助商链接



  本文“<b>一段可以下载文件的源代码</b>[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

// 在工程中加入 Urlmon.lib
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#include <Urlmon.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
cImpMonikerCallback objImpCallback;
//---------------------------------------------------------------------------
#pragma argsused
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  LPUNKNOWN pCaller;
  pCaller = NULL;
  DWORD dwResv = 0;
  objImpCallback.lpfnCB = (IBindStatusCallback *)&objImpCallback;
  HRESULT hRet=URLDownloadToFile(pCaller,"http://127.0.0.1:30000/download/icon.zip","d:\\temp\\icon.zip",dwResv,objImpCallback.lpfnCB);
  if(hRet==S_OK)
   MessageBox(NULL,"成功下载文件","",MB_OK);
  return 0;
}
//---------------------------------------------------------------------------
cImpMonikerCallback::cImpMonikerCallback()
{
  m_cRef = 1;
  m_pbinding = NULL;
};
//---------------------------------------------------------------------------
cImpMonikerCallback::~cImpMonikerCallback()
{
  if(m_pbinding)
   m_pbinding->Release();
};
//---------------------------------------------------------------------------
STDMETHODIMP cImpMonikerCallback::QueryInterface(REFIID riid,void ** ppv)
{
  *ppv = NULL;
  if (riid==IID_IUnknown ¦¦ riid==IID_IBindStatusCallback)
  {
   *ppv = this;
   AddRef();
   return S_OK;
  }
  return E_NOINTERFACE;
};
//---------------------------------------------------------------------------
STDMETHODIMP_(ULONG) cImpMonikerCallback::AddRef()
{
  return m_cRef++;
}
//---------------------------------------------------------------------------
STDMETHODIMP_(ULONG) cImpMonikerCallback::Release()
{
  if(--m_cRef==0)
  {
   delete this;
   return 0;
  }
  return m_cRef;
}
//---------------------------------------------------------------------------
STDMETHODIMP cImpMonikerCallback::GetBindInfo(DWORD* pgrfBINDF, BINDINFO* pbindinfo)
{
  return(NOERROR);
}
//---------------------------------------------------------------------------
STDMETHODIMP cImpMonikerCallback::OnStartBinding(DWORD grfBSCOption, IBinding* pbinding)
{
  return(NOERROR);
}
//---------------------------------------------------------------------------
STDMETHODIMP cImpMonikerCallback::GetPriority(LONG* pnPriority)
{
  return(NOERROR);
}
//---------------------------------------------------------------------------
STDMETHODIMP cImpMonikerCallback::OnProgress(ULONG ulProgress, ULONG ulProgressMax,ULONG ulStatusCode, LPCWSTR szStatusText)
{
  return(NOERROR);
};
//---------------------------------------------------------------------------
STDMETHODIMP cImpMonikerCallback::OnDataAvailable(DWORD grfBSCF, DWORD dwSize, FORMATETC *pfmtetc,STGMEDIUM* pstgmed)
{
  return(NOERROR);
}
//---------------------------------------------------------------------------
STDMETHODIMP cImpMonikerCallback::OnObjectAvailable(REFIID riid, IUnknown* punk)
{
  return(NOERROR);
}
//---------------------------------------------------------------------------
STDMETHODIMP cImpMonikerCallback::OnLowResource(DWORD dwReserved)
{
  return(NOERROR);
}
//---------------------------------------------------------------------------
STDMETHODIMP cImpMonikerCallback::OnStopBinding(HRESULT hrStatus, LPCWSTR szText)
{
  return(NOERROR);
}
//---------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
class cImpMonikerCallback:public IBindStatusCallback
{
  DWORD m_cRef;
  IBinding* m_pbinding;
public:
     cImpMonikerCallback();
     ~cImpMonikerCallback();
     STDMETHODIMP QueryInterface(REFIID riid,void ** ppv);
     STDMETHODIMP_(ULONG) AddRef();//  { return m_cRef++; }
  STDMETHODIMP_(ULONG) Release();
     STDMETHODIMP GetBindInfo(DWORD* pgrfBINDF, BINDINFO* pbindinfo);
     STDMETHODIMP OnStartBinding(DWORD grfBSCOption, IBinding* pbinding);
     STDMETHODIMP GetPriority(LONG* pnPriority);
     STDMETHODIMP OnProgress(ULONG ulProgress, ULONG ulProgressMax,ULONG ulStatusCode, LPCWSTR szStatusText);
     STDMETHODIMP OnDataAvailable(DWORD grfBSCF, DWORD dwSize, FORMATETC *pfmtetc,STGMEDIUM* pstgmed);
     STDMETHODIMP OnObjectAvailable(REFIID riid, IUnknown* punk);
     STDMETHODIMP OnLowResource(DWORD dwReserved);
     STDMETHODIMP OnStopBinding(HRESULT hrStatus, LPCWSTR szText);
     LPBINDSTATUSCALLBACK lpfnCB;
     PSTR sURL;
     PSTR sFile;
  char cSysDir[MAX_PATH];
  DWORD dwPlatform;
};


  以上是“<b>一段可以下载文件的源代码</b>[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
  • <b>hosts是什么 hosts文件在什么位置 若何改正hosts</b>
  • <b>在 Windows 8 中手动安装语言包</b>
  • <b>五个常见 PHP数据库问题</b>
  • Windows中Alt键的12个高效快速的利用本领介绍
  • <b>MySQL ORDER BY 的实现解析</b>
  • <b>详解MySQL存储历程参数有三种范例(in、out、inout)</b>
  • <b>Win8系统恢复出来经典的开始菜单的办法</b>
  • <b>Win8系统花屏怎么办 Win8系统花屏的办理办法</b>
  • <b>Windows 7系统下无线网卡安装</b>
  • <b>为什么 Linux不需求碎片整理</b>
  • <b>Windows 8中删除账户的几种办法(图)</b>
  • <b>教你如安在win7下配置路由器</b>
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .