Un module qui fait tout planter !!!

Un module qui fait tout planter !!! - VB/VBA/VBS - Programmation

Marsh Posté le 23-08-2002 à 18:33:49    

Voici le module  

Code :
  1. Option Explicit
  2. Public 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
  3. Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hOpen As Long, ByVal sUrl As String, ByVal sHeaders As String, ByVal lLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
  4. Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
  5. Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
  6. Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
  7. Public Const INTERNET_OPEN_TYPE_DIRECT = 1
  8. Public Const INTERNET_OPEN_TYPE_PROXY = 3
  9. Public Const scUserAgent = "VB OpenUrl"
  10. Public Const INTERNET_FLAG_RELOAD = &H80000000
  11. Sub Download(URL As String, SaveAs As String)
  12.         Dim hOpen                            As Long
  13.         Dim hOpenUrl                        As Long
  14.         Dim bDoLoop                      As Boolean
  15.         Dim bRet                                As Boolean
  16.         Dim sReadBuffer              As String * 2048
  17.         Dim lNumberOfBytesRead  As Long
  18.         Dim sBuffer                      As String
  19.         hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
  20.         hOpenUrl = InternetOpenUrl(hOpen, URL, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
  21.         bDoLoop = True
  22.         While bDoLoop
  23.                 sReadBuffer = vbNullString
  24.                 bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
  25.                 sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead)
  26.                 If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
  27.              
  28.                
  29.         Wend
  30.        
  31.         Open SaveAs For Binary Access Write As #1
  32.         Put #1, , sBuffer
  33.         Close #1
  34.        
  35.         If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
  36.         If hOpen <> 0 Then InternetCloseHandle (hOpen)
  37. End Sub


Quand j'utilise ce module  
en l'appelant par

Code :
  1. call download ("www.grosficheir.com/grosficheir.Exe","c:\gff.exe" )


par exemple  
Le programme ne va plus répondre (on ne peux plus bouger la fenetre ni appuyer sur les boutons il plante quoi )tant que le fichier ne sera pas télécharger  
quand il a fini de le télécharger  
tout redevient normal
POURQUOI ?
S'il vous plait  aidez moi  :cry:  :cry:  

Reply

Marsh Posté le 23-08-2002 à 18:33:49   

Reply

Marsh Posté le 23-08-2002 à 21:37:28    

met un DoEvents juste avant le Wend dans ta boucle. Si ca plante tjrs, un sleep(10) devrait faire l'affaire.

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed