Solved

WININET: Error handling a timeout

Posted on 2004-08-23
8
269 Views
Last Modified: 2008-03-04
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.
0
Comment
Question by:kinton
  • 3
  • 2
8 Comments
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11868910
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
0
 
LVL 2

Author Comment

by:kinton
ID: 11869315
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.
0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 250 total points
ID: 11869440
Check this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/option_flags.asp
I think that you can handle timeout if you set propriate flags
0
 
LVL 2

Author Comment

by:kinton
ID: 12345431
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.
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12563927
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now