Solved

WININET: Error handling a timeout

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 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