Error trying to use URLDownloadFileW

860 views Asked by At

I'm trying to download a zip file from a link using the URLDownloadFileW function. The part of the code that I've developed by now with this function is:

UnicodeString URL = "URL.EX";
UnicodeString dir = "C:\";
UnicodeString result = URLDownloadToFileW(NULL,URL.c_str(),dir.c_str(),0,NULL);
if (result != "S_OK")
    return;

And I have declared the Urlmon.h on the header, however, when I build the project it returns me:

[ilink32 Error] Error: Unresolved external 'URLDownloadToFileW' referenced from C:\USERS\ADMINISTRADOR\DESKTOP\SD MANUTENÇÃO\WIN32\DEBUG\SDSUPER449.OBJ
[ilink32 Error] Error: Unable to perform link

I'm not finding any usable search result about it. Does someone have any idea what does it mean?

1

There are 1 answers

5
Remy Lebeau On BEST ANSWER

urlmon.h is needed for the compiler to compile your code. The compiler creates a reference to the URLDownloadToFileW function, but doesn't care where the function exists. That is the linker's job to figure out.

urlmon.lib is needed for the linker to resolve the compiler's reference to the URLDownloadToFileW function.

RAD Studio has both files, in the $(BDS)\include\win32\sdk and $(BDS)\lib\win32\release folders, respectively.

You need to do both:

  1. add an #include <urlmon.h> statement in the code.

  2. link to the urlmon.lib file, by either adding the file to the project, or by referencing it in a #pragma comment(lib, "urlmon.lib") statement in the code.

You are missing step #2, which is why you are getting a linker error.