?
Solved

WinINet problem with InternetGetLastResponseInfo method.  Program ends without error.

Posted on 2007-08-10
7
Medium Priority
?
1,372 Views
Last Modified: 2013-11-26
I have an unattended process that pull TIFF files from a remote server.  I'm using the WinINet.dll for the FTP functions.  I use the FtpGetFile function to copy down the file, and if successful, I use the FtpDeleteFile function to remove the file from the source directory.  This process has to run thru a proxy server, and during certain periods of heavy usage, the transfers are extremely slow.  As a result, the proxy sometimes drops the connection while the file is transferring.  Although the transfer completes, the attempt to delete the source file fails because the connection is no longer active.  I'm trying to find a reliable way to check the connection following the transfer before attempting the delete, or at least capture the error information when FtpDeleteFile fails.

I'm trying to use the InternetGetLastResponseInfo function to get any useful error numbers and text so that I can proceed accordingly.  The following is a copy of my DeleteFile method.:

Public Function DeleteFile(FileToDelete As String) As Boolean
Dim lBuffSize As Long
Dim lError As Long
Dim sErrDesc As String
   On Error GoTo ErrorHandler
    'Delete the file
    If Not FtpDeleteFile(m_hConnection, FileToDelete) Then
        'Attempt to retrieve FTP error info.
        If Err.LastDllError = ERROR_INTERNET_EXTENDED_ERROR Then
            InternetGetLastResponseInfo lError, vbNullString, lBuffSize
            sErrDesc = String$(lBuffSize + 1, vbNullChar)
            InternetGetLastResponseInfo lError, sErrDesc, lBuffSize                '***********
            Err.Raise ERR_ON_DELETE, , sErrDesc & vbCr & vbCr & _
                "Error occured while trying to delete file " & FileToDelete & " on the remote server."
        Else
            lError = Err.LastDllError
            sErrDesc = GetDLLErrorText(lError)
            Err.Raise lError, , sErrDesc
        End If
    End If
ErrorHandler:
    If Err.Number <> 0 Then
        m_lErrNum = Err.Number
        m_sErrDesc = Err.Description
        Err.Clear
        DeleteFile = False
    End If
End Function

The variable m_hConnection is the handle returned by the original OpenConnection call.  My problem is that the second call to InternetGetLastResponseInfo completely aborts my program (without any error message).  In my IDE, when I step thru the execution, same thing.  No error, nothing, IDE simply closes.

The WinINet.dll version I have is 6.0.2800.1596.  Both my dev machine and the server that the application runs on are Win2000 SP4 (5.0.2195)
0
Comment
Question by:BMarq
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:drichards
ID: 19671829
Have you looked at the FtpWebRequest class?  It is much easier to use in that it automatically opens a new connection if one does not already exist.  Since it's part of the .NET framework, error handling is also much easier.  It might be faster to switch out the FTP code than to try to diagnose these issues with WinINet.

Docs are at http://msdn2.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx is you are interested.

Simple delete file example from docs:

    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
    request.Method = WebRequestMethods.Ftp.DeleteFile;
    FtpWebResponse response = (FtpWebResponse) request.GetResponse();
    Console.WriteLine("Delete status: {0}",response.StatusDescription);  
    response.Close();

If you set the KeepAlive property the connection will not close and the next FTP request will reuse it to the same server.
0
 

Author Comment

by:BMarq
ID: 19671868
Currently, I'm limited to VB6 for this particular application.  I will discuss with the customer about converting part or all of the application to .NET, but in the meantime, need to get this one going.
0
 
LVL 19

Expert Comment

by:drichards
ID: 19672068
The only thing I see that might be a problem with your code is that lBuffSize should be incremented prior to the second call to InternetGetLastResponseInfo because you have (correctly) allocated lBuffSize+1 characters on the string.  Doesn't seem that would cause termination of your program, though.

The other issue is how you have declared the InternetGetLastResponseInfo function for use by VB.  Maybe it is not correct somehow.  Using an incorrect pointer could case termination of your program.

And if you are in VB6 you should post in the Visual Basic section rather than then VB.NET section to avoid responses like my first one - it really is easier, though ;)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:BMarq
ID: 19672362
I apologize for the post in the wrong zone, this is my first time.  Although I think I should have gotten it to both zones, I'll go back and check.

I tried the increment, no change in behavior.  Here is my API declaration:

Private Declare Function InternetGetLastResponseInfo _
    Lib "WinInet.dll" Alias "InternetGetLastResponseInfoA" _
    (ByRef lpdwError As Long, ByRef lpszErrorBuffer As String, _
     ByRef lpdwErrorBufferLength As Long) As Boolean
0
 
LVL 19

Expert Comment

by:drichards
ID: 19673393
It's been a while since I did this kind of stuff, but does it let you define the String parameter as ByVal?
0
 
LVL 19

Accepted Solution

by:
drichards earned 2000 total points
ID: 19673864
I did a quick search on Google and it appears that changing the String param to ByVal is correct.  That's probably what is crashing your program.
0
 

Author Comment

by:BMarq
ID: 19683733
The change to ByVal did the trick.  Thank you so much.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

830 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