<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++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |