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.
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.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
I think that http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/option_flags.asp is the correct answer
Private Declare Function InternetGetLastResponseInf
Sub ShowError()
Dim lErr As Long, sErr As String, lenBuf As Long
'get the required buffer size
InternetGetLastResponseInf
'create a buffer
sErr = String(lenBuf, 0)
'retrieve the last respons info
InternetGetLastResponseInf
'show the last response info
MsgBox "Error " + CStr(lErr) + ": " + sErr, vbOKOnly + vbCritical
End Sub
If hfile = 0 Then ShowError