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

    Unhappy downloading problem

    I use URLdownloadtofile to download a 5MB file, but why does it silently stop at 120KB the downloaded part becomes an invalid win32 application ?
    Could someone explain ?
    I read MSDN and see that this APi only allows download size less than 4GB, I'd like my application to dowload unlimited file size, and wonder how I can do this too.
    In my Console appliation, only that function is used, nothing more.

    Thank you.
    Last edited by somedaysomewhere; March 13th, 2011 at 12:20 PM.
    ...

  2. #2
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: downloading problem

    some months back I wrote this small code for grabbing a piece of jpg..

    Code:
    	char szName [180];
    	char dwnUrl[] = "http://a.imageshack.us/img42/2705/crol.jpg";
    	HANDLE hF;
    
    	URLDownloadToCacheFileA (0, dwnUrl, szName, 180, BINDF_GETNEWESTVERSION, 0);
    	hF = CreateFileA (szName, GENERIC_READ, 0, 0,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL ,0);
    
    	if (hF == INVALID_HANDLE_VALUE)
    	{
    		CloseHandle(hF);
    		return false;
    	}
    
    	if (GetFileSize (hF, 0) == 26053)
    	{
    		CloseHandle(hF);
    		return true;
    	}
    	
    	else 
    	{
    		CloseHandle(hF);
    		return false;
    	}
    though this code worked fine with larger files. be sure that you are not closing the file handle before downloading completes.
    ◄◄ hypheni ►►

  3. #3
    Join Date
    Mar 2011
    Posts
    46

    Re: downloading problem

    Remember URLDownloadToFile only begins the download you must provide a LPBINDSTATUSCALLBACK function to monitor its progress or simply periodically
    or loop check the downloaded file size against the size you started to download.

    A return of S_OK from URLDownloadToFile only means The download started successfully it does not mean it completed.

    Without seeing your code my guess is you get S_OK back and then drop thru to use the file but a large file will still be downloading.

  4. #4
    Join Date
    Dec 2010
    Posts
    41

    Re: downloading problem

    hi, it works finally, thanks for your guides.
    ...

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