Results 1 to 3 of 3

Thread: Use of InternetReadFile

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    60
    I am writing a small ftp program and have a question -

    I realize there is a function called FtpGetFile but this does not allow for the monitoring of bytes recieved. If it does then I am not aware of how to use it.

    I am trying to create a recieving progress bar. I already have the send progress bar and use InternetWriteFile to accomplish this. With InternetWriteFile I assumed I could use InternetReadFile in about the same way. Below is my current - non working - idea


    Dim Data_A(99) As Byte
    Dim Written As Long, szFileRemote As String, szFileLocal As String
    Dim bDoLoop As Boolean

    szFileRemote = List1.Text
    szFileLocal = List1.Text

    hFile = FtpOpenFile(hConnection, szFileRemote, &H40000000, dwType, 0)

    If hFile = 0 Then
    ErrorOut Err.LastDllError, "FtpOpenFile"
    Exit Function
    End If
    Open szFileLocal For Binary As #1
    bDoLoop = True
    While bDoLoop
    InternetReadFile hFile, Data_A(0), Len(Data_A(0)), Written
    Put #1, , Left$(Data_A(0), Written)
    If Not CBool(Written) Then bDoLoop = False
    Wend

    Close #1

    InternetCloseHandle (hFile)

    Please if someone could help me with this I would be very gracious.

  2. #2
    Guest
    Not sure if this'll help, but here is an example from the API-Guide (http://www.allapi.net) using the InternetReadFile API function.



    Code:
    Const scUserAgent = "API-Guide test program"
    Const INTERNET_OPEN_TYPE_DIRECT = 1
    Const INTERNET_OPEN_TYPE_PROXY = 3
    Const INTERNET_FLAG_RELOAD = &H80000000
    Const sURL = "http://www.microsoft.com/index.htm"
    Private Declare Function InternetOpen Lib "wininet" 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 InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
    Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead 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 Sub Form_Load()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
           
        Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
        'Create a buffer for the file we're going to download
        sBuffer = Space(1000)
        'Create an internet connection
        hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
        'Open the url
        hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
        'Read the first 1000 bytes of the file
        InternetReadFile hFile, sBuffer, 1000, Ret
        'clean up
        InternetCloseHandle hFile
        InternetCloseHandle hOpen
        'Show our file
        MsgBox sBuffer
    End Sub

  3. #3
    Lively Member
    Join Date
    Oct 2000
    Posts
    72
    Matthew, how do u avoid the program locking when the url u pass it doesn't resolve?

    I have looked through loads of documentation and can't find anything to validate that the URL is available for connection.

    Any ideas?

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