Link to home
Start Free TrialLog in
Avatar of kinton
kinton

asked on

WININET: Error handling a timeout

I have a program that uses Wininet to connect to an FTP site.  First it downloads an ini file, then it downloads some update files.

If there is a delay between the 2 processes a timeout occurs, however, it doesnt actually give an error.  Is there a way that I can detect if a session handle is still active?

If there isn't, the only thing I can think of is to attempt a re-connect once, but I'd prefer to determine if the connection is active.  My code that deals with this so far is:

hfile = FtpOpenFile(ServerID, fName, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0)
                 If hfile = 0 Then
                   MsgBox "Failed but I dont know why!"
                  Exit Function
            End If

Any help would be great thanks.
Avatar of mladenovicz
mladenovicz

You can get error with this code

Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean

Sub ShowError()
    Dim lErr As Long, sErr As String, lenBuf As Long
    'get the required buffer size
    InternetGetLastResponseInfo lErr, sErr, lenBuf
    'create a buffer
    sErr = String(lenBuf, 0)
    'retrieve the last respons info
    InternetGetLastResponseInfo lErr, sErr, lenBuf
    'show the last response info
    MsgBox "Error " + CStr(lErr) + ": " + sErr, vbOKOnly + vbCritical
End Sub

If hfile = 0 Then ShowError
Avatar of kinton

ASKER

Hi mladenovicz,

Thanks for the code, unfortunately it didnt pick it up as an error.  Useful peice of code all the same though so i'm sure i'll put it to good use.
ASKER CERTIFIED SOLUTION
Avatar of mladenovicz
mladenovicz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kinton

ASKER

Hi mladenovicz,

Thanks for the link, I will be looking into it but currently i've switched to working on some internal databases so haven't had/wont have the time to continue looking into this problem.... but I will!

I'll let you know just as soon as I've finished my internal apps and im back on the project.