Solved

WININET: Error handling a timeout

Posted on 2004-08-23
8
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

615 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