Results 1 to 7 of 7

Thread: [RESOLVED] VB6: Software freezes while downloading a file from web!

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    May 2012
    Location
    La Plata, Buenos Aires, Argentina
    Posts
    52

    Resolved [RESOLVED] VB6: Software freezes while downloading a file from web!

    Hi.
    I have a big software already running in many companies.
    As a measure of security, I want to add to it a module that checks in a website (ftp with username & password) if I want the program to block it self, or send messages to user, or update it self, etc.

    It download the file perfectly! The problem is it takes a little while to do it (like 3-5 seconds, and if it's offline, like a minute) and during it, the whole software freezes until it ends. I tried moving the routine to another form, but it's the same. I also thought of moving it to an independent exe that triggers when the main one runs, but nowadays Windows is so paranoic it would be very caotic (sandbox, firewall...) it has to do it quietly.

    Any suggestions? I'm thinking of doing it when the program closes, or when it's inactive for 1 minute, but still, it's awkward and it just can't freeze like that, my clients are going to report it to me. TO SUM UP, I need it to do it quietly, silently, in background, no freezing (or at least that if it's offline, doesn't freeze for 1 minute).


    The code I use is:

    Code:
    Option Explicit
    Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    Private Declare Function InternetOpen Lib "wininet" 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 InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
    
    Function InternetGetFile(sURLFileName As String, sSaveToFile As String, Optional bOverwriteExisting As Boolean = False) As Boolean
        Dim lRet As Long
        Const S_OK As Long = 0, E_OUTOFMEMORY = &H8007000E
        Const INTERNET_OPEN_TYPE_PRECONFIG = 0, INTERNET_FLAG_EXISTING_CONNECT = &H20000000
        Const INTERNET_OPEN_TYPE_DIRECT = 1, INTERNET_OPEN_TYPE_PROXY = 3
        Const INTERNET_FLAG_RELOAD = &H80000000
        
        On Error Resume Next
        'Create an internet connection
        lRet = InternetOpen("", INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)   '---> in this line it freezes and I can't do anything
        
        If bOverwriteExisting Then
            If Len(Dir$(sSaveToFile)) Then
                VBA.Kill sSaveToFile
            End If
        End If
        'Check file doesn't already exist
        If Len(Dir$(sSaveToFile)) = 0 Then
            'Download file
            lRet = URLDownloadToFile(0&, sURLFileName, sSaveToFile, 0&, 0)
            If Len(Dir$(sSaveToFile)) Then
                'File successfully downloaded
                InternetGetFile = True
            Else
                'Failed to download file
                If lRet = E_OUTOFMEMORY Then
                    EscribeLog "Error serv: The buffer length is invalid or there was insufficient memory to complete the operation."
                Else
                    EscribeLog "Error serv: (this is probably a proxy server error)." 'Escribelog is a function on my own, it's "WriteLog" in spanish
                End If
                InternetGetFile = False
            End If
        End If
        On Error GoTo 0
        
    End Function
    and I call it this way:
    Code:
    Public Sub RevWeb()
        On Error Resume Next
        Dim ppArch As String, pp As String, sn As String, accion As String, param As String, pplocal As String
        ppArch = App.Path + "\" + Format(Date + Time, "ddmmyyhhmmss")
        If InternetGetFile("adress/file.txt", ppArch, True) Then  '---> in this line it freezes!
            'it opens and processes the content of the file, now in hard disk
        End If
    End Sub
    THANK YOU VERY MUCH.
    PS: English is not my native language, please excuse my grammar or spelling errors.
    Last edited by IHappenToBe'; Dec 13th, 2012 at 12:08 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width