URLDownloadToFile() not allowing the program to return value
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

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

  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,422

    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
    Wallisellen (ZH), Switzerland
    Posts
    17,269

    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,422

    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
    5,923

    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
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center