Home > Windows API > Download files from Internet through code

Download files from Internet through code

Use URLDownloadToFile.

An article on this API is here, with a demo application.

Advertisements
  1. karlt
    August 27, 2008 at 10:16 pm

    Yami, BITS is a COM object, so there’s no reason why you shouldn’t be able to use it, so long as your copy of VC 6 is up to date- check MSDN to be sure. Please feel free, to drop me a line if you want some sample code and I’ll send it to you. Be warned though, that BITS is designed to use spare bandwidth, so any solution you come up with may not be as fast as URLDownloadToFile. Good luck, Karl

  2. August 6, 2008 at 5:34 am

    🙂

    Karl has given his e m a i l address, maybe you can try asking him.

  3. Yami
    August 6, 2008 at 4:25 am

    I got the same problem of “hanging” upon losing connection (unplug) while using URLDownloadToFile(). The program only prompt my callback AFTER I plug back and have internet connection. I’m using VC6 and I’m not sure if BITS is available. Any help will be appreciated.

  4. karl
    June 16, 2008 at 7:38 pm

    Finally managed to get my BITS replacement for URLDownlodToFile working.

    It’s not the prettiest piece of code I’ve ever written, since I’ve had to Mac Guyver it to do what I wanted. Oh well, all part of the joy of programming I suppose. If anyone has any problems with URLDownloadToFile, drop me a line at tomlinsonkarl A-T-H-O-T-M-A-I-L-D-O-T-C-O-M AND I’ll send you a copy of what I wrote. It’s not pretty, but it may help.

  5. June 13, 2008 at 2:38 pm

    I like function UrlDownloadToFile, hope MS will fix such issues! If BITS works then it’s worth the effort! 🙂

    All the best!

  6. Karl
    June 13, 2008 at 2:35 pm

    Hi Nibu,
    the code that I was looking at was (I think) something by Chris Maunder, whose excellent website has saved my bacon on innumerable occasions. But not this time, sadly. I’m really beginning to get annoyed with Vista.

    Over on the MSDN forums, it seemed that someone else was having a similar problem with URLDownloadToFile, and it was suggested that they try using BITS (Background Intelligent Transfer Service). This is a great pity since I’ve now replaced an elegant one line function call (albeit with a separate callback) with a hundred or so lines of mostly boilerplate COM! Oh well, that’s progress, I suppose.

  7. June 12, 2008 at 1:59 pm

    Yeah looks bit clunky, but if it works should be fine since we don’t have another option. 🙂

    By the way is that Chris or Michael Dunn. 😉

  8. Karl
    June 12, 2008 at 1:38 pm

    Hi Nibu,
    thanks for the reply. I noticed Chris’s article a while back, but a quick glance at his code gave me an idea:

    if ( m_bUseTimeout && CTime::GetCurrentTime() > m_timeToStop )
    return E_ABORT;

    It’s a bit clunky but I’ll give it a whirl. Thanks for pointing me in that direction.

    Karl

  9. June 12, 2008 at 1:08 pm

    Karl,

    There is an article in CodeProject with a demo application, here is the link
    http://www.codeproject.com/KB/IP/urldownload.aspx.

    I don’t have vista hence can’t say, Hope this link gives you some help!

  10. Karl
    June 12, 2008 at 1:03 pm

    Hi Nibu,
    UrlDownloadToFile is a great function- efficient and easy to implement a callback to. But… let’s say you call UrlDownloadToFile and lose your network connection. Under XP, the function exits, and one can start to pick up the pieces. Under vista, the function just hangs- there’s no indication of an error condition, not even through the callback. Any ideas?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: