DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Get Remote File Size (API) [HttpQueryInfo]

  1. #1
    Join Date
    Apr 2006

    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)

  2. #2
    Join Date
    Nov 2003
    Portland, OR
    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

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Apr 2006

    That worked.

Similar Threads

  1. Replies: 1
    Last Post: 08-27-2002, 11:50 AM
  2. database file size
    By Carlos Paiva in forum VB Classic
    Replies: 3
    Last Post: 04-19-2002, 07:58 AM
  3. Replies: 0
    Last Post: 04-17-2000, 01:33 PM
  4. Replies: 0
    Last Post: 04-17-2000, 01:29 PM
  5. 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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center