Module Module2
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Declare Auto Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Integer, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Integer, ByVal dwFlags As Integer, ByVal dwContext As Integer) As Integer
Private Declare Auto Function InternetReadFile Lib "wininet" (ByVal hFile As Integer, ByVal sBuffer As String, ByVal lNumBytesToRead As Integer, ByVal lNumberofBytesRead As Integer) As Integer
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Declare Auto Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Integer, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Integer) As Integer
Friend Declare Auto Function InternetCloseHandle Lib "wininet" (ByRef hInet) As Integer
Friend hOpen As Integer
Friend Sub ShowTitle()
hOpen = InternetOpen("App1", INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
Dim sBuffer As String = Space(1000) 1000 characters must surely be enough.
Dim hFile As Integer
Dim Ret As Integer
Dim sPath As String = "http://www.google.co.uk/"
hFile = InternetOpenUrl(hOpen, sPath, vbNullString, 0&, INTERNET_FLAG_RELOAD, 0&)
InternetReadFile(hFile, sBuffer, 1000, Ret)
InternetCloseHandle(hFile)
Debug.Print(sBuffer)
Dim t1 As Long
Dim t2 As Long
t1 = InStr(sBuffer, "<TITLE>") + 7
t2 = InStr(sBuffer, "</TITLE>")
If t1 <> 0 And t2 <> 0 Then Debug.Print(Mid$(sBuffer, t1, t2 - t1))
InternetCloseHandle(hOpen)
End Sub
End Module