Re: InternetReadFileEx
- From: JonWayn <JonWayn@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 01:26:02 -0700
Thanks, but it fails, returning error #6 to the debug window. What is the
interpretation of that error?
"Mike D Sutton" wrote:
.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/
- Follow-Ups:
- Re: InternetReadFileEx
- From: Mike D Sutton
- Re: InternetReadFileEx
- References:
- Re: InternetReadFileEx
- From: Mike D Sutton
- Re: InternetReadFileEx
- Prev by Date: Re: how to change Z-orders of Windows
- Next by Date: Re: How I make a DLL work with Excel/Word VBA?
- Previous by thread: Re: InternetReadFileEx
- Next by thread: Re: InternetReadFileEx
- Index(es):
Relevant Pages
|