[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

10/11/2005 at 02:45PM PDT, ID: 21591651
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Finally FTP Wininet Async Callback, BUT...

Asked by egl1044 in Visual Basic Programming

Tags: wininet

Hello, By Default the WinInet API is Sync which doesn't allow your form to be responsive at all until the file is downloaded, I have managed to finally get WinInet API working in Async operation using the Microsoft article below. I need to know if I set this up correctly, I need expert input on my code. Initially there is always a small delay until it finally gets into the callback proc. But this is much better than it blocking it all together, after about a 3 second delay it will download async and you can perform other operations on the same form, etc.. populate listbox's and such while its downloading..

INFO: Using WinInet APIs Asynchronously Within Visual Basic
http://support.microsoft.com/kb/q189850/

When leaving the callback proc empy it seems the form errors our with (not responding) but its still performs async operations. So I had to figure out someway to make the form stop from saying (Not Responding). By adding Doevents call into the CallBack Proc seems to work without problems.
If anyone has done this before could you shed some light on issue. As for now it works perfect when adding DoEvents into the Callback proc, but there has to be something I am doing wrong. Thanks - egl

* Feel free to try out this code and see for yourself *

'------------ FTPasync.cls ----------------

Option Explicit
'http://support.microsoft.com/kb/q189850/

Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet As Long) As Long

Private Declare Function InternetOpen Lib "WININET.dll" Alias "InternetOpenA" _
   (ByVal sAgent As String, _
    ByVal lAccessType As Long, _
    ByVal sProxyName As String, _
    ByVal sProxyBypass As String, _
    ByVal lFlags As Long) As Long

Private Declare Function InternetConnect Lib "WININET.dll" Alias "InternetConnectA" _
   (ByVal hInternetSession As Long, _
    ByVal sServerName As String, _
    ByVal nServerPort As Integer, _
    ByVal sUsername As String, _
    ByVal sPassword As String, _
    ByVal lService As Long, _
    ByVal lFlags As Long, _
    ByVal lcontext As Long) As Long

Private Declare Function InternetSetStatusCallback Lib "WININET.dll" _
   (ByVal hInternetSession As Long, _
    ByVal lpfnInternetCallback As Long) As Long

Private Declare Function FtpGetFile Lib "WININET.dll" Alias "FtpGetFileA" _
   (ByVal hFtpSession As Long, _
    ByVal lpszRemoteFile As String, _
    ByVal lpszNewFile As String, _
    ByVal fFailIfExists As Boolean, _
    ByVal dwFlagsAndAttributes As Long, _
    ByVal dwFlags As Long, _
    ByVal dwContext As Long) As Boolean

Event AsyncDownloadComplete()

Sub DownloadAsync(RemoteFile As String, _
                    LocalFile As String, _
                    HostAddr As String, _
                    UserID As String, _
                    Password As String)
   
   Const nFlag As Long = 0
   Const dwType As Long = 0
   Const lcontext As Long = 2
   Const lAccess As Long = 1
   Const dContext As Long = 2
   Const FTP_DIRECT As Long = 1
   Const FTP_SERVICE As Long = 1
   Const FTP_RELOAD As Long = &H80000000
   Const uAgent As String = "ASYNC"

        hOpen = InternetOpen(uAgent, lAccess, vbNullString, vbNullString, FTP_DIRECT)
        hConnection = InternetConnect(hOpen, HostAddr, 21, UserID, Password, FTP_SERVICE, nFlag, lcontext)

   If hConnection <> 0 Then
        lRet = InternetSetStatusCallback(hConnection, AddressOf MyCallBack)
        lRes = FtpGetFile(hConnection, RemoteFile, LocalFile, False, FTP_RELOAD, dwType, dContext)
   End If
       
        lRes = InternetCloseHandle(hConnection)
        lRes = InternetCloseHandle(hOpen)
       
        RaiseEvent AsyncDownloadComplete
End Sub



'----------- modCallback.bas -----------------

Option Explicit

Public hOpen As Long
Public hConnection As Long
Public lRet As Long
Public lRes As Long

Public Sub MyCallBack(ByVal hOpen As Long, _
            ByVal dwContext As Long, _
            ByVal dwInternetStatus As Long, _
            ByVal lpdwStatusInformation As Long, _
            ByVal dwStatusInformationLength As Long)
           
    Form1.Caption = "Downloading ASYNC NOW!"
           
    DoEvents 'This works to avoid form error NOT RESPONDING!
           
End Sub


'Enter FTP settings below:
'------------- Form1 ----------------

Option Explicit

Private WithEvents FA As FTPasync

Private Sub Command1_Click()

Call FA.DownloadAsync("ProjectBackups.zip", _
                        "D:\ProjectBackups.zip", _
                        "ftp.server.com", _
                        "username", _
                        "password")

End Sub

Private Sub FA_AsyncDownloadComplete()
MsgBox "Download Complete"
End Sub

Private Sub Form_Load()
If FA Is Nothing Then Set FA = New FTPasync
End Sub

Private Sub Form_Unload(Cancel As Integer)
If Not FA Is Nothing Then Set FA = Nothing
End Sub
[+][-]10/11/05 06:04 PM, ID: 15065619

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10/11/05 08:57 PM, ID: 15066042

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/17/05 07:37 PM, ID: 15104533

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/18/05 05:06 AM, ID: 15106492

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/18/05 05:32 AM, ID: 15106661

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/18/05 06:00 AM, ID: 15106897

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Basic Programming
Tags: wininet
Sign Up Now!
Solution Provided By: EDDYKT
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10/18/05 07:55 AM, ID: 15108080

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/19/05 09:46 AM, ID: 15117574

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74