Here's how I download a file (or URL) with Visual Basic that is very reliable and has never failed to work for me. Perhaps someone can translate it to its PureBasic equivalent?To get the webpage we can use wininet.dll too
(InternetOpen, InternetOpenUrl, InternetReadFile and InternetCloseHandle functions) BUT the problem remains the same... the buffer.
How can we work arround it?
Code: Select all
' Download a file (or URL) from the Internet
Dim url As String, filedata As String
url = "[url]http://www.google.com/images/logo.gif[/url]"
hOpen = InternetOpen("VB OpenUrl", 0, vbNullString, vbNullString, 0)
hOpenUrl = InternetOpenUrl(hOpen, url, vbNullString, 0, &H80000000, 0)
bDoLoop = True
While bDoLoop
iBuffer = vbNullString
bRet = InternetReadFile(hOpenUrl, iBuffer, Len(iBuffer), bytesread)
filedata = filedata & Left(iBuffer, bytesread)
If Not CBool(bytesread) Then bDoLoop = False
Wend
If hOpenUrl 0 Then InternetCloseHandle (hOpenUrl)
If hOpen 0 Then InternetCloseHandle (hOpen)
MsgBox filedata
' To save to disk (add required extension of downloaded file):
Open "c:\file" For Binary Access Write As #1
Put #1, , filedata
Close #1
PB - Registered PureBasic Coder