Attribute VB_Name = "ModGoWinInet"
Option Explicit

Const INTERNET_OPEN_TYPE_PRECONFIG = 0

'Get data even if it is locally cached.
' - no need to call deleteUrlCache API !
Const INTERNET_FLAG_RELOAD = &H80000000

'· dwFlags - Action flags. Can be one of these values:
'INTERNET_FLAG_RELOAD
'Get the data from the wire even if it is locally cached.
'
'INTERNET_FLAG_DONT_CACHE
'Do not cache the data, either locally or in any gateways.
'
'INTERNET_FLAG_RAW_DATA
'Return raw data (WIN32_FIND_DATA structures for FTP, and GOPHER_FIND_DATA structures for Gopher). If this flag is not specified, InternetOpenUrl returns HTML formatted for directories.
'
'INTERNET_FLAG_SECURE
'Request secure transactions on the wire with Secure Sockets Layer or PCT. This flag applies to HTTP requests only.
'
'INTERNET_FLAG_EXISTING_CONNECT
'If possible, reuse the existing connections to the server for new requests generated by InternetOpenUrl instead of creating a new session for each request.

'Const INTERNET_FLAG_EXISITING_CONNECT = &H20000000


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

Private Declare Function InternetCloseHandle Lib _
    "wininet.dll" (ByVal hInet As Long) As Integer

Public Function GoWinInet(sURL$) As String
    Dim sBuffer As String * 4096, sReturn As String
    Dim lNumBytes As Long, lSession As Long, lFile As Long
    Dim bReadOK As Boolean
    lSession = InternetOpen("GSInternet", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    lFile = InternetOpenUrl(lSession, sURL, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
    If lFile Then
        Do
            bReadOK = InternetReadFile(lFile, sBuffer, Len(sBuffer), lNumBytes)
            If lNumBytes Then
            sReturn = sReturn & Left$(sBuffer, lNumBytes)
            End If
        Loop While bReadOK And lNumBytes > 0
        InternetCloseHandle (lFile)
        GoWinInet = sReturn
    End If
End Function

