[C] HTTP-Downloader

Ask your beginner questions here.
Post Reply
KarNak
Posts: 7
Joined: Sun Dec 30, 2018 1:48 pm

[C] HTTP-Downloader

Post by KarNak » Sat Jan 12, 2019 11:32 am

Small/Clean HTTP Downloader (c)

Use this clean code in most my projects,

-Rex
You do not have the required permissions to view the files attached to this post.

User avatar
Brock
Posts: 209
Joined: Wed Apr 28, 2010 3:13 am
Location: Valparaiso, Florida USA
Contact:

Re: [C] HTTP-Downloader

Post by Brock » Sun Jan 13, 2019 12:14 am

Took a quick peek at the code, don't forget to close thread and process handles upon successful call returns. Only mentioning this because you mentioned the word "clean" twice and these are resource leaks.

Download.cpp

download_thread() --->
CloseHandle(pInfo->hThread);
CloseHandle(pInfo->hProcess);

download_DialogProc() --->
HANDLE hThread = CreateThread(..., ..);
if (hThread) {
CloseHandle(hThread);
}

For downloading to disk as a file directly (not memory) there exists the API URLDownloadToFile inside URLMon. Seems you likely have more of a *nix background so perhaps you weren't aware of it in the world of Windows. Would be an improvement if you added proxy and SSL support as well to it, these days it's almost required for anything done with remote sockets, and it's very simple to do with WinInet functionality.

Thanks for sharing, although I wonder if the more appropriate section of this forum is the Newbie area (can be more helpful to those learning there)
Accept nothing less than STATUS_SUCCESS

KarNak
Posts: 7
Joined: Sun Dec 30, 2018 1:48 pm

Re: [C] HTTP-Downloader

Post by KarNak » Sun Jan 13, 2019 1:25 pm

Thank you for the correction brock.

User avatar
mrfearless
Posts: 4
Joined: Fri Feb 19, 2016 10:09 pm
Location: Ireland
Contact:

Re: [C] HTTP-Downloader

Post by mrfearless » Mon Jan 14, 2019 4:46 pm

A downside to using URLDownloadToFile, (that i found but perhaps i have overlooked something) is that it uses a cache, so if your downloading a file again it will just use the cached version. I found that problematic when creating an auto update library and fetching a version text file (or other files). If the file name is the same (as previously downloaded and cached), but content has changed, you will get the older version, before the cache is expired at some later time (i think).

If anyone has any advice/experience with additional net api calls to avoid this issue that will be cool. I ended up coding manually something myself that uses the wininet api calls to do something similar.

User avatar
Brock
Posts: 209
Joined: Wed Apr 28, 2010 3:13 am
Location: Valparaiso, Florida USA
Contact:

Re: [C] HTTP-Downloader

Post by Brock » Tue Jan 15, 2019 1:42 pm

Accept nothing less than STATUS_SUCCESS

Post Reply