Qbasicnews.com
Downloading a file from internet? - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: Downloading a file from internet? (/thread-6193.html)



Downloading a file from internet? - gbos - 02-22-2005

I tried to make it work in freebasic but no luck so far :oops:

It is supposed to download a txt file from a specific location. It compiles fine but it doesn’t download the file. Any thoughts what I am doing wrong.

Code:
'' Function FGetFileHTTP_URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByRef szURL As String, ByRef szFileName As String,ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
'$include: 'win\kernel32.bi'
Dim dummy as long
Dim url$
Dim OFile$
url$="http://www.ase.gr/content/gr/MarketData/Stocks/Prices/Files/txt/20050221.txt"
OFile$="quotes.txt"
Dim FGetFileHTTP_URLDownloadToFile as function (ByVal pCaller As Long, ByRef szURL As String, ByRef szFileName As String,ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
   dim hlib as integer
   hlib = LoadLibrary("urlmon.dll")
   FGetFileHTTP_URLDownloadToFile = GetProcAddress( hlib, "URLDownloadToFileA" )
   dummy = FGetFileHTTP_URLDownloadToFile (0, url$, OFile$,0, 0)
sleep



Downloading a file from internet? - Antoni Gual - 02-22-2005

Perhaps you're supposed to open a socket using winsock before calling this function...


Downloading a file from internet? - v3cz0r - 02-22-2005

Try redeclaring all string arguments as BYVAL, that will tell FB to pass the address of the string data (that what the API wants), not the string descriptor (that what BYREF will do).


Downloading a file from internet? - gbos - 02-22-2005

:bounce: Thanks a lot !!! The code is working now.

Code:
'$include: 'win\kernel32.bi'
Dim dummy as long
Dim url$
Dim OFile$
url$="http://www.ase.gr/content/gr/MarketData/Stocks/Prices/Files/txt/20050221.txt"
OFile$="quotes.txt"
Dim FGetFileHTTP_URLDownloadToFile as function (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String,ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
   dim hlib as integer
   hlib = LoadLibrary("urlmon.dll")
   FGetFileHTTP_URLDownloadToFile = GetProcAddress( hlib, "URLDownloadToFileA" )
   dummy = FGetFileHTTP_URLDownloadToFile (0, url$, OFile$,0, 0)
sleep