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)