CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Jun 2013
    Posts
    2

    URLDownloadToFile() not allowing the program to return value

    Hello guys.
    I am new here, hope we will have good time together.

    I've been writing some code and this is part of it:
    Code:
    ...
    URLDownloadToFile(NULL, _T("http://something/something.txt"), path, 0, NULL);
    return 0;
    }
    The file gets downloaded successfully but the downloader wont exit (return value 0). So it remains active.
    I am sure the problem is URLDownloadToFile()
    Anyone have idea what's going on?
    I am using Visual Studio 2010 Express.

    Thanks for your time.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: URLDownloadToFile() not allowing the program to return value

    Quote Originally Posted by darkyzzw0w View Post
    I am sure the problem is URLDownloadToFile()
    Where is your check of the return code of URLDownloadToFile? What does that function return?

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Jun 2013
    Posts
    2

    Re: URLDownloadToFile() not allowing the program to return value

    When I remove that line, the program exists successfully, and with it, it wont end.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: URLDownloadToFile() not allowing the program to return value

    Quote Originally Posted by darkyzzw0w View Post
    When I remove that line, the program exists successfully, and with it, it wont end.
    How long did you wait for the URLDownloadToFile return?
    How did you know that "file gets downloaded successfully"?
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: URLDownloadToFile() not allowing the program to return value

    Quote Originally Posted by darkyzzw0w View Post
    When I remove that line, the program exists successfully, and with it, it wont end.
    That is not what I asked.

    What is the return code from URLDownLoadToFile?

    When you call an API function that is documented to return a value back to you, you're code should be checking the return code. Just assuming that functions "work" without checking return codes is not the way to use an API properly.

    Regards,

    Paul McKenzie

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

    Re: URLDownloadToFile() not allowing the program to return value

    Quote Originally Posted by darkyzzw0w View Post
    I am sure the problem is URLDownloadToFile()
    And I'm sure it's not.
    Code:
    #include <windows.h>
    #include <urlmon.h>
    #include <stdio.h>
    #pragma comment(lib, "urlmon.lib")
    
    int main()
    {
        HRESULT hr = URLDownloadToFile (NULL, __argv[1], "foofoo.bin", 0, NULL);
        printf("%s\n", SUCCEEDED(hr) ? "Success" : "Failed");
        return 0;
    }
    Code:
    E:\Temp\694>694.exe http://msdn.microsoft.com/en-us/library/ms775123%28v=vs.85%29.aspx
    Success
    foofoo.bin
    Code:
    <!DOCTYPE html>
    
    <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
        <head><link rel="canonical" href="http://msdn.microsoft.com/en-us/library/ms775123(v=vs.85).aspx" />
            <title>URLDownloadToFile function (Windows)</title>
            <script type="text/javascript" src="http://i2.msdn.microsoft.com/Areas/Epx/Content/Scripts/modernizr2.custom.epx.js" data-do-not-move="true"> </script>
    
    
    
    
    <meta name="DCS.dcsuri" content="/en-us/library/ms775123(d=default,l=en-us,v=vs.85).aspx" />
    
    <meta name="NormalizedUrl" content="http://msdn.microsoft.com/en-us/library/ms775123(d=default,l=en-us,v=vs.85).aspx" />
    
    <meta name="VotingContextUrl" content="http://msdn.microsoft.com/en-us/library/ms775123(d=default,l=en-us,v=vs.85).aspx" />
    
    <meta name="MN" content="FB361393-2:51:11 AM" />
    
    <meta name="Search.ShortId" content="ms775123" />
    
    <meta name="Ms.Locale" content="en-us" />
    
    . . .
    Last edited by Igor Vartanov; June 4th, 2013 at 04:58 AM.
    Best regards,
    Igor

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

    Re: URLDownloadToFile() not allowing the program to return value

    Quote Originally Posted by darkyzzw0w View Post

    I've been writing some code and this is part of it:
    Code:
    ...
    URLDownloadToFile(NULL, _T("http://something/something.txt"), path, 0, NULL);
    return 0;
    }
    The file gets downloaded successfully but the downloader wont exit (return value 0). So it remains active.
    I am sure the problem is URLDownloadToFile()
    How is path defined?

    Please produce a full working test program that demonstrates the problem (like Igor posted) and post the program here.
    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)

Tags for this Thread

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