1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| Option Explicit
Public Enum TypeDeFichier
FichierAscii = False
FichierBinaire = True
End Enum
Public Declare Function InternetOpen Lib "wininet.dll" _
Alias "InternetOpenA" _
(ByVal lpszAgent As String, _
ByVal dwAccessType As Long, _
ByVal lpszProxyName As String, _
ByVal lpszProxyBypass As String, _
ByVal dwFlags As Long) _
As Long
Public Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Long
Public 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
Public Declare Function InternetReadFile Lib "wininet.dll" _
(ByVal hFile As Long, _
ByVal lpBuffer As String, _
ByVal dwNumberOfBytesToRead As Long, _
lNumberOfBytesRead As Long) _
As Long
Public Declare Function DeleteUrlCacheEntry Lib "wininet.dll" _
Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) _
As Integer
Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_FLAG_RELOAD = &H80000000
Public hSession As Long
Public hUrlFile As Long
Public Function OuvrirURL(sURL As String, FileType As TypeDeFichier) As String
Dim Buffer As String * 256
Dim Info As String
Dim NombreOctets As Long
Dim ValRet As Long
Dim R As Integer
Screen.MousePointer = vbHourglass
On Error GoTo Err_Lecture
DeleteUrlCacheEntry sURL
hSession = InternetOpen(App.Title, _
INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, _
vbNullString, _
0)
hUrlFile = InternetOpenUrl(hSession, _
sURL, _
vbNullString, _
0, _
INTERNET_FLAG_RELOAD, _
0)
Dim Total As Long
Select Case FileType
Case True
'Synopsis.PB1.Max = Total
'Total = 0
Do
ValRet = InternetReadFile(hUrlFile, _
Buffer, _
Len(Buffer), _
NombreOctets)
If NombreOctets > 0 Then Info = Info & Buffer
'Total = Total + NombreOctets
'Synopsis.PB1.Value = Total
DoEvents
Loop Until NombreOctets = 0
'Synopsis.PB1.Value = 0
InternetCloseHandle (hUrlFile)
InternetCloseHandle (hSession)
If Len(Info) = 0 Then
OuvrirURL = False
Screen.MousePointer = vbNormal
Exit Function
End If
Case False
ValRet = InternetReadFile(hUrlFile, _
Buffer, _
Len(Buffer), _
NombreOctets)
InternetCloseHandle (hUrlFile)
InternetCloseHandle (hSession)
If NombreOctets = 0 Then
OuvrirURL = False
Screen.MousePointer = vbNormal
Exit Function
End If
Info = Left$(Buffer, NombreOctets)
End Select
DeleteUrlCacheEntry sURL
Screen.MousePointer = vbNormal
OuvrirURL = Info
Exit Function
Err_Lecture:
OuvrirURL = False
Screen.MousePointer = vbNormal
Exit Function
End Function |
Partager