The URLDownloadToFile
function may fail due to various reasons, such as incorrect URL, network connectivity issues, or security settings. One possible reason for the failure on a new install could be related to proxy server settings. According to Microsoft documentation, the URLDownloadToFile
function uses the Urlmon.dll
file to handle all Internet transitions. If the request goes through a proxy server, the proxy server may deny access, resulting in a failure. One workaround is to use ShellExecute()
on the URL, which allows the operating system to start the URL on the default browser. If the default browser isn't restricted by the proxy server, the proper page is displayed.
In your case, since GetLastError()
returns 0, it may not be related to proxy server settings. You may want to check if the URL is correct and accessible. Also, you may want to try using other functions, such as WinHttpOpen
, WinHttpConnect
, and WinHttpOpenRequest
, to download the file. These functions provide more control over the HTTP request and may give you more information about the failure.
References:
- Error message when selecting hyperlink in Office: "Cannot locate the Internet server or proxy server"
- Error Handling in WinHTTP
- Handling Uniform Resource Locators
- Uniform Resource Locators (URLs) in WinHTTP
- Error Handling in COM (Get Started with Win32 and C++)