Download file from internet

General FreeBASIC programming questions.
Sisophon2001
Posts: 1702
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Download file from internet

Postby Sisophon2001 » Oct 02, 2005 10:31

Hi:

This is a demo of downloading a file from the internet using the WinAPI.

My VC++ help file says

Windows NT: Use version 5.0 or later.
Windows: Unsupported.

But I am nearly sure “URLDownloadToFileA” works on all versions of Windows? I tested on WinXP.

Does it work on older systems?

Have fun

Garvan

Code: Select all

option explicit
   dim i

function downloadfromweb (byval szURL as zstring ptr, _
      byval szFileName as zstring ptr) as integer

   dim r as integer
   dim library as integer
   dim URLDownloadToFile as function (byval pCaller as any ptr, _
      byval szURL as zstring ptr, _
      byval szFileName as zstring ptr, byval dwResv as uinteger, _
      byval lpfnCB as any ptr) as integer

   library = dylibload("urlmon")
   if library = 0 then return 1
   URLDownloadToFile = dylibsymbol (library, "URLDownloadToFileA")
   if URLDownloadToFile = 0 then return 1

   r = URLDownloadToFile(0, szURL, szFileName, 0, 0)

   function = r
end function

   print "Downloading..."
   i = downloadfromweb("http://www.freewebs.com/weekendcode/FBStyle.zip","FBStyle.zip")
   if i = 0 then print "Download suceeded" else print "Download failed"
   sleep


EDIT:
The return 0 will not work so I changed it to return 1 to generate an error if the DLL or function cannot be found
Last edited by Sisophon2001 on Oct 02, 2005 11:25, edited 2 times in total.
mjs
Site Admin
Posts: 842
Joined: Jun 16, 2005 19:50
Location: Germany

Postby mjs » Oct 02, 2005 10:43

This is from the MSDN Library:

Function Information

  • Stock Implementation
    urlmon.dll
  • Custom Implementation
    No
  • Header
    Urlmon.h
  • Import library
    Urlmon.lib
  • Minimum availability
    Internet Explorer 3.0
  • Minimum operating systems
    Windows NT 4.0, Windows 95
  • Unicode
    Implemented as ANSI and Unicode versions


Regards,
Mark
Sisophon2001
Posts: 1702
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Postby Sisophon2001 » Oct 02, 2005 11:27

Thanks mjs

If it is part of Internet Explorer, then that helps explains the difference between the help sources.

Garvan
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Postby Antoni » May 01, 2009 11:27

I have tested the code above and it worked in XP for a bunch of jpeg files i wanted to rip from a site
To make it compile in 0.20 just redefine the variable library as any ptr and remove the option explicit line

Return to “General”

Who is online

Users browsing this forum: No registered users and 5 guests