Re: InternetReadFileEx

Tech-Archive recommends: Fix windows errors by optimizing your registry



Anybody here knows how to successfully use InternetReadFileEX. In
particular
the settings for the INTERNET_BUFFERS structure properties: This structure
has an embedded INTERNET_BUFFERS property. What are the possible settings
for
this?

Try something like this:

'***
Private Declare Function InternetReadFileEx Lib "WinINet.dll" Alias
"InternetReadFileExA" ( _
ByVal hFile As Long, ByRef lpBuffersOut As INTERNET_BUFFERS, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Long

Private Type INTERNET_BUFFERS
dwStructSize As Long
Next As Long
lpcszHeader As Long ' LPCTSTR
dwHeadersLength As Long
dwHeadersTotal As Long
lpvBuffer As Long ' LPVIOD
dwBufferLength As Long
dwBufferTotal As Long
dwOffsetLow As Long
dwOffsetHigh As Long
End Type

Const WININET_API_FLAG_ASYNC As Long = &H1 ' Force async operation
Const IRF_ASYNC As Long = WININET_API_FLAG_ASYNC

....

Const BufLen As Long = 1024

Dim hNetFile As Long
Dim OutBuffer As INTERNET_BUFFERS
Dim Buffer(0 To BufLen - 1) As Byte

' Open file
hNetFile = InternetOpenUrl( ... )
If (hNetFile) Then
' Set up return buffer structure
OutBuffer.dwStructSize = Len(OutBuffer)
OutBuffer.dwBufferLength = BufLen
OutBuffer.lpvBuffer = VarPtr(Buffer(0))

' Attempt to read first chunk from file
If (InternetReadFileEx(hNetFile, OutBuffer, IRF_ASYNC, 0&)) Then
Do While OutBuffer.dwBufferLength > 0
' Do something with this buffer (0 to OutBuffer.dwBufferLength -
1 bytes)
Call InternetReadFileEx(hNetFile, OutBuffer, IRF_ASYNC, 0&)
Loop
Else
Debug.Print "InternetReadFileEx error: " & CStr(Err.LastDllError)
End If
End If

' Close file
Call InternetCloseHandle(hNetFile)
'***

Don't try and use the Unicode version of the function, it seems that it's
not implemented and will simply fail if you try.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@xxxxxxxx
WWW: Http://EDais.mvps.org/


.