Click here to Skip to main content
13,254,077 members (60,081 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 12 Jan 2012

Alternative to URLDownloadToFile function

, 13 Jan 2012
Rate this:
Please Sign up or sign in to vote.
How to download files from an HTTP server.

In response to a StackOverflow question[^], I developed an alternative for URLDownloadToFile function; it is based on a generic HTTP client[^] written in C++.

CString FormatErrorMessage(DWORD dwLastError)
     const int nLength = 0x1000;
     TCHAR lpszBuffer[nLength] = { 0 };
     if (::FormatMessage(
         (LPTSTR) &lpszBuffer,
         nLength, NULL) == 0)
         _stprintf_s(lpszBuffer, nLength, _T("Unknown INET error 0x%.4X\n"), dwLastError);
     return lpszBuffer;
HRESULT DownloadURLToFile(CString strURLDownload, CString strFilePath)
     CHTTPClient httpClient;
     BOOL bResult = httpClient.Request(
     DWORD dwLastError = httpClient.GetLastError();
     OutputDebugString(_T("DownloadURLToFile: ") + FormatErrorMessage(dwLastError));
     LPBYTE lpszHttpResponse = httpClient.QueryHTTPResponse();
     return (bResult ? S_OK : E_FAIL);


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mihai MOGA
Architect Printec Group Romania SRL
Romania Romania
My professional background includes knowledge of analyst programmer for Microsoft Visual C++, Microsoft Visual C#, Microsoft Visual Basic, Sun Java, assembly for Intel 80x86 microprocessors, assembly for PIC microcontrollers (produced by Microchip Inc.), relational databases (MySQL, Oracle, SQL Server), concurrent version systems, bug tracking systems, web design (HTML5, CSS3, XML, PHP/MySQL, JavaScript, Flash).

If you like my articles, please visit my website for more:

You may also be interested in...

Comments and Discussions

GeneralPlease Can you tell me how to show Upload and Download in gr... Pin
Member 856969016-Jan-12 20:13
memberMember 856969016-Jan-12 20:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 13 Jan 2012
Article Copyright 2012 by Mihai MOGA
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid