Solved

WININET: Error handling a timeout

Posted on 2004-08-23
8
270 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

17 Experts available now in Live!

Get 1:1 Help Now