would you know why URLDownloadToFile fails on windows 10

Lloyd Etheridge 20 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,562 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,609 questions
{count} votes

Accepted answer
  1. Neuvi Jiang 1,300 Reputation points Microsoft Vendor
    2024-09-20T07:44:06.7133333+00:00

    Hi Lloyd Etheridge,

    Thank you for posting in the Q&A Forums.

    Dependencies issue:

    Ensure that all necessary libraries and runtime environments are installed on your system. URLDownloadToFile is part of Internet Explorer, so make sure that IE or one of its related components (e.g. URLMon.dll) is properly installed and registered.

    Check that all necessary updates and patches are installed on your system.

    Permission issues:

    Make sure your application has enough permissions to access the destination folder and write to files. In some cases, you may need to run your application as an administrator.

    Check the permission settings of the destination folder to ensure that the application's user account has appropriate read and write permissions.

    Firewall or security software:

    Firewalls or security software may prevent applications from accessing the network or writing to files. Check to see if any security software is preventing URLDownloadToFile from operating.

    URL problems:

    Make sure that the URL you are trying to download is valid and that the server allows downloads from your IP address.

    Try accessing the URL in your browser to see if the file downloads successfully.

    Debugging and logging:

    Add more logging to your application to get a more detailed view of what happens before and after the URLDownloadToFile call.

    Use a debugging tool such as Visual Studio's debugger to step through the code and check for any possible exceptions or errors when calling URLDownloadToFile.

    Code Review:

    Double-check your code to make sure that all the parameters of URLDownloadToFile are correct. In particular, the URL and file path must be valid and formatted correctly.

    Make sure that no other API calls affect the error code before calling URLDownloadToFile (for example, by calling SetLastError(0)).

    Use an alternative download method:

    If possible, try using another method (such as the WinHTTP or WinInet APIs) to download the file to troubleshoot URLDownloadToFile-specific issues.

    Check the system event log:

    Check the System Log and Application Log in the Windows Event Viewer for errors or warnings related to your application or related components.

    Best regards

    NeuviJ

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

1 additional 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:


    1 person found this answer helpful.

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.