URLDownloadToFile question *resolved*-VBForums
Results 1 to 25 of 25

Thread: URLDownloadToFile question *resolved*

  1. #1

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    URLDownloadToFile question *resolved*

    I am using URLDownloadToFile in an auto update application i am writing for my main application.

    I got everything working, but is there anyway I can cancel a download that has been started using that API call? If I simply terminate the exe, the file still continues to download.

    I want to give the user the ability to click a cancel button to opt out of downloading if they need to for some reason.

    I am using Edanmo's olelib.tlb file so that I could impliment the IBindStatusCallback interface to make a progress bar and all that... it works fine.. I just need to be able to cancel it.

    The API guide says this about the function
    lpfnCB
    Address of the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data. IBindStatusCallback::OnDataAvailable is never called. Implementing IBindStatusCallback::OnProgress allows a caller to implement a user interface or other progress monitoring functionality. It also allows the download operation to be canceled by returning E_ABORT from the IBindStatusCallback::OnProgress call. This can be set to NULL.
    but I am unsure of how to return E_ABORT from the OnProgress call, as it is a sub and not a function (at least in Edanmo's olelib.tlb implimentation it is)
    Last edited by kleinma; Jan 22nd, 2004 at 05:39 PM.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  2. #2

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383
    solved it....

    but for anyone who is interested....

    I dimmed an object (objBind) of type IBinding

    in the IBindStatusCallback_OnStartBinding call I set the object to pib (which is passed into this method)

    I also set it to nothing in the IBindStatusCallback_OnStopBinding method.

    I was then able to create a sub and call it from my form
    Code:
    Sub AbortDownload()
        If Not objBind Is Nothing Then
            objBind.Abort
        End If
    End Sub
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  3. #3
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633
    There is not a thread on VBF that covers this topic correctly
    Many people use the URLDownloadToFiLe API, but it seems that no-one knows what to pass in for the lpfnCB param of this API.
    My form implements IBindStatusCallback but the progress sub doesn't fire. This I know if due to be not passing the correct param into the URLDownloadToFile API...

    Any ideas...?

    Woof

  4. #4

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383
    it does now doesn't it
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633
    No
    Was working till silly o'clock last night.
    Had a few hrs sleep.
    had a dream about a dog getting squished my a lorry, very gory Woke up and decided to come to work and smash my computer...hahahaha.

    *yawn*

    Stupid code *sulk*

    Gonna start from scratch and write it line by line and see if I can get it to work.

    Woof

  6. #6
    Banned DiGiTalErRoR's Avatar
    Join Date
    Sep 2002
    Posts
    68
    I just coded my own winsock downloader.... Complete control!

  7. #7

  8. #8
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by DiGiTalErRoR
    I just coded my own winsock downloader.... Complete control!
    dig what happened to all your posts ?

  9. #9

  10. #10
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by Wokawidget
    hahahaha...68...NOOB!

    Not gonna take any advice from you now.



    awooooooo awooooooo HONK HONK!
    he used to be in the thousands...

    VB Code:
    1. UPDATE Posts SET PostCount=0 WHERE UserName= 'DiGiTalErRoR'



    Edit: Damn hax0r username.

  11. #11
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    For simplicity, I would also like to know how to get the URLDownloadToFile function to report progress and be able to cancel the operation. If sombody could please post some code about how to do this successfully, I would be rally grateful. It seems that there is little documentation about how to do this...

    TIA
    Mike

    PS: Please see my related post: http://www.vbforums.com/showthread.p...hreadid=295984


    [UPDATE] OK I have searched the forums and the links to mvps... are not working. Also the links to the edanmo type library are not working out OK...
    Last edited by MikkyThomeon; Jul 2nd, 2004 at 04:06 PM.

  12. #12
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648

  13. #13
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633
    I have got it working.
    And boy does it work perfectly

    However, I emailed the code to myself from work, but it hasn't appeared
    Not happy as I was gonna do some alterations.

    I am at work tmrw. The code will be posted here in under 14 hrs Sorry about this.

    It's actually dead easy to do, and I have no idea why there isn't much documentation on the web about it

    There is however one thing I have found wrong with it. If you want your app to silently download soemthing from the web then it only works if you do not have a download manager installed on your PC, like DAP. If you do then this launches and takes over your download!!! This is VERY VERY annoying and I can't seem to stop it, apart from uninstalling the download manager. Booooooooooooooo


    Woof

  14. #14
    Fanatic Member alexandros's Avatar
    Join Date
    Oct 2002
    Location
    Milky Way Galaxy
    Posts
    694
    in my humble opinion it is time to use .NET for this type of internet programming

  15. #15
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633
    I have to agree with you here, but alas, when someone knows VB6 VERY well, and their entire app is in VB6, and they do not have .NET then other solutions must be found. Fact of development.

    Anyways, the link to the tlb files is:

    http://www.mvps.org/emorcillo/vb6/tlb/olelib.shtml

    Download the zip, and copy the tlb files to your System32 folder and register them. Instructions are on the page.

    These tlb files allow you to create callback functions.

    Now, download my the zip, and run it.
    There isn't much coding involved and the general VB stuff is quite basic. It helps if you know how call backs work, but this isn't important as you can still modify the code without this knowledge.

    This example has the preset source of the AllAPI's APIGuide. This is what it downloads. The file is about 2.5Mb.

    It's dead annoying while testing as you have to keep deleting the file from the temp internet files folder other wise the download takes about 0 seconds

    If you need any help give me a shout.

    Regards,

    Woof
    Attached Files Attached Files

  16. #16
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    Have to agree with you about .NET!!!!!!

    The project I have been working on involves knowing almost everything about the most common internet protocols around just to get the thing working. And then dealing with network events.... My app is extensively event driven and it is a nightmare putting all the modules together!!!

  17. #17

  18. #18

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383
    Originally posted by Wokawidget


    It's dead annoying while testing as you have to keep deleting the file from the temp internet files folder other wise the download takes about 0 seconds

    Woof
    that is why you write a kill line in your code to kill the temp internet file each time
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  19. #19

  20. #20

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383
    you can show hidden files, or even then it still does't let you call kill on it because its marked as hidden?
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  21. #21

  22. #22
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    Hi Woka

    I have been pulled off that and am working hell for leather to get an random encrytion decryption / privat key scheme working.

    Hanv not forgotten!!! Will be ready for more stuff after Friday. Thanks for your response. You are always attentive when someone has a problem and I do appreciate that fact!!! On the weekend I will have more time and be able to tackle the issue...

  23. #23
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    No this method sux because of files being cached locally. It is alseo a bit too much of a heavyweight implementation for my app and is somewhat of an overkill. I will stick to the winsock method where I have complete control and no freezing etc.

  24. #24
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648

    multithread

    No this method sux because of files being cached locally. It is alseo a bit too much of a heavyweight implementation for my app and is somewhat of an overkill. I will stick to the winsock method where I have complete control and no freezing etc.

  25. #25
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    http://www.vbforums.com/showthread.p...nsock+download

    Apparently you can set a different flag in the URLDownloadToFile call and that will force the newer version to be downloaded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.