I have used the Microsoft WINAPI syntax from here.

So, here is my code

#include <windows.h> #pragma comment(lib, "urlmon.lib") HRESULT URLDownloadToFileW( FALSE, "", "C:\\psych0bOx.png", 0, NULL); 

When i try to compile it with VS12.0 I get these errors:

C:\\>cl C:\URLDownloadToFileA.cpp C:\URLDownloadToFileA.cpp(8) : error C2365: 'URLDownloadToFileA' : redéfinition ; la précédente définition était 'fonction' C:\Program Files\Windows Kits\8.1\include\um\urlmon.h(4780) : voir la déclaration de 'URLDownloadToFileA' C:\URLDownloadToFileA.cpp(8) : error C2078: initialiseurs trop nombreux C:\\> 

I don't understand why I get these errors. I'm completely blocked here.

1

1 Answer

Try:

HRESULT hr = URLDownloadToFileW( FALSE, L"", L"C:\\psych0bOx.png", 0, NULL); 

Note that hr is a variable of type HRESULT. When URLDownloadToFileW function returns hr gets assigned some sort of status value you can check. Probably you can find out if the function downloaded correctly.

Without the hr the compiler thinks you are redefining URLDownloadToFileW, hence the compiler error.

Note also that the W on the end indicates a Unicode function so you need to build your project as Unicode. And because it is a Unicode function you must pass in Unicode string - that is why they are preppended with L - means Unicode.

Alternatively use URLDownloadToFileA or URLDownloadToFile and do not define Unicode.

I just looked up the function (which you could have done) and you will need to do a lot more to make any use of this function. First thing is to provide the last argument.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.