CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2010
    Posts
    12

    URLDownloadToFile() not working?

    Hi,

    In a program I've written I'm using the code URLDownloadToFile(NULL,source_location,target_location,0,NULL) to download a small file from source_location on the internet to target_location on disk. This code works perfectly fine for both me and virtually everyone who uses the program. However, a very small percentage of users seems to have trouble in getting this to work. The file is not downloaded for them. Particularly these people seem to have either Kaspersky installed or no protection at all.

    Now, I fully understand that they should just set an exception, however this doesn't seem to solve the issue for some reason. The program can still not connect, even with an exception.

    Does anyone have any idea of what could be causing this?
    Or if there's some method of figuring out what is the cause of the block?
    Or if possibly I'm not using URLDownloadToFile correctly?

    Thanks in advance!

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: URLDownloadToFile() not working?

    Definitely you have to analyze returned error code. So, do you?
    Best regards,
    Igor

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: URLDownloadToFile() not working?

    It would be useful if you posted the actual code used - or provide a complete simple program that exhibited the problem.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    Aug 2010
    Posts
    12

    Re: URLDownloadToFile() not working?

    Well, the code is pretty basic:

    CString savetodisc=GetFilePathForProgram()+CString("thefile.txt");
    CString downloadlocation=CString("http://www.mywebsite.com/thefile.txt");
    HRESULT hr=URLDownloadToFile(NULL,downloadlocation,savetodisc,0,NULL);

    It works fine for >99% of all users, including myself, so at this point I have no real means of analyzing why this doesn't work for <1% of users. I'm perfectly capable of letting one of them run some tests of what is going wrong, but I'd like some sort of idea of where to look first.

    Once again, this is an issue that only seems to occur for people who either use Kaspersky or no firewall/virus scanner at all.
    And most people with this setup can connect anyhow, so it's not an issue that is easily reproduced.
    Setting an exception or disabling the firewall/virusscanner does not seem to have any effect.
    The file is not downloaded at all, it simply ends up having a size of 0kb.

    I was just wondering if anyone has ever run into this issue?
    Or possibly there's some alternate way of downloading a file that I might try?
    Is there some way to track down what caused the block?

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: URLDownloadToFile() not working?

    As per post #2, what is the value of hr when the function does not work. Every time a function is used that can return error codes, these codes should be checked and appropriate action taken. You say that for some users, the file is not downloaded. Does the download start, get partway through and fail, not start at all or just start, hang and not return ?? Have you looked at the network traffic via something like WireShark? URLDownloadToFile has the capability to use notification callback so that the calling program can be notified of progress. If you use this facility then more information might be able to be obtained as to the cause of the problem.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured