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(
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dwLastError,
0,
(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;
httpClient.EnableStatusCallback(TRUE);
httpClient.InitilizePostArguments();
httpClient.SetDownloadFile(strFilePath);
BOOL bResult = httpClient.Request(
strURLDownload,
CHTTPClient::RequestGetMethod,
__DEFAULT_AGENT_NAME);
DWORD dwLastError = httpClient.GetLastError();
OutputDebugString(_T("DownloadURLToFile: ") + FormatErrorMessage(dwLastError));
LPBYTE lpszHttpResponse = httpClient.QueryHTTPResponse();
return (bResult ? S_OK : E_FAIL);
}
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).
Latest project:
IntelliEdit, the best replacement for Microsoft Notepad!