A piece of source code that can download files

Source: Internet
Author: User
Tags zip

Adding Urlmon.lib
to the project

//---------------------------------------------------------------------------


#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, "Successful download File", "", 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*);


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;


};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.