would you know why URLDownloadToFile fails on windows 10

Lloyd Etheridge 0 Reputation points
2024-09-19T08:58:29.7833333+00:00

I have compiled code using watcom c++ compilier under win32 using the function URLDownloadToFile and while this was working on other machines its not working on a brand new install.

#include <urlmon.h>

HANDLE hr = URLDownloadToFile(NULL, "https://www.eziaccounts.net.au/receipt.txt", "receipt.txt", 0, NULL);

GetLastError() returns 0 which sheds no light onto the reason its failing,

any ideas would be helpful

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,500 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,592 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2024-09-19T08:58:29.8+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    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:


    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.