Results 1 to 11 of 11

Thread: Problem with InternetReadFile

Threaded View

  1. #1

    Thread Starter
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Problem with InternetReadFile

    I've been using this library function to download pages from the internet, and it's worked great for months.
    Code:
    Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
    Private Declare Function InternetOpenUrl Lib "wininet.dll" 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 InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
    
    Public Function DownloadURL(pstrURL As String) As String
        Const INTERNET_OPEN_TYPE_PRECONFIG = 0
        Const INTERNET_FLAG_RELOAD = &H80000000
        Dim strBuffer As String * 4096
        Dim strReturn As String
        Dim lngLen As Long
        Dim lngSession As Long
        Dim lngFile As Long
        Dim blnSuccess As Boolean
        
        lngSession = InternetOpen("GSInternet", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
        lngFile = InternetOpenUrl(lngSession, pstrURL, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
        If lngFile Then
            Do
                blnSuccess = InternetReadFile(lngFile, strBuffer, Len(strBuffer), lngLen)
                If lngLen Then strReturn = strReturn & Left$(strBuffer, lngLen)
            Loop While blnSuccess And lngLen > 0
            InternetCloseHandle (lngFile)
            DownloadURL = strReturn
        End If
    End Function
    Now it doesn't work anymore. The problem is that the server seems to have a delay in it. When browsing manually, much of the page gets drawn, then there's a second or two delay, then the rest of the page gets drawn.

    That second or two delay seems to be killing the above utility function. What happens now is the function only returns the half of the page that gets sent before the second or two delay.

    Does anyone know how or why this would happen, and any way to fix it?
    Last edited by Ellis Dee; Jun 24th, 2009 at 11:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width