-
Get Remote File Size (API) [HttpQueryInfo]
Hi all
I have a problem with the following code. Everytime I execute it VB crashes at line HttpQueryInfo...
Private Declare Function HttpQueryInfo Lib "wininet.dll" Alias "HttpQueryInfoA" (ByVal hHttpRequest As Long, ByVal lInfoLevel As Long, ByRef sBuffer As Any, ByRef lBufferLength As Long, ByRef lIndex As Long) As Boolean
Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
'When I download (the variables & constants used are defined):
hInternet = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
'I check if handler is correct
hFile = InternetOpenUrl(Connection.hInternet, strURL, vbNullString, 0, 0, 0)
'I check if handler is correct
'I try to get the file size (I have the URL & the handler to the file)
strBuffer = String$(1024, 0)
Call HttpQueryInfo(ByVal hFile, HTTP_QUERY_CONTENT_LENGTH, strBuffer, Len(strBuffer), 0) 'Here crashes VB
lngSize = Val(strBuffer)
'But if I skip the file size I can read & save the file on my computer using the function InternetReadFile
So can you tell me what is wrong with this code?
But if you cannot find the error, do you know any other ways to get the file size using the url?
On FTP, I can use the function:
Private Declare Function FtpGetFileSize Lib "wininet.dll" (ByVal hFile As Long, ByRef lpdwFileSizeHigh As Long) As Long
(this one works only on FTP)
-
You need to pass strBuffer ByVal, and I think you need to pass buffer length in a variable, since it's ByRef:
lBufLen = Len(strBuffer)
Call HttpQueryInfo(hFile, HTTP_QUERY_CONTENT_LENGTH, _
ByVal strBuffer, lBufLen, 0)
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Similar Threads
-
By Phani in forum VB Classic
Replies: 1
Last Post: 08-27-2002, 11:50 AM
-
By Carlos Paiva in forum VB Classic
Replies: 3
Last Post: 04-19-2002, 07:58 AM
-
By deborah in forum authorevents.kurata
Replies: 0
Last Post: 04-17-2000, 01:33 PM
-
By Ranadeep in forum authorevents.kurata
Replies: 0
Last Post: 04-17-2000, 01:29 PM
-
By - John of Arc - in forum VB Classic
Replies: 0
Last Post: 03-31-2000, 12:45 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|