c++ - UrlToDownloadFile function not downloading -
i using urltodownloadfile function, doesn't download file. no error shown in compiler (using vstudio 2012)
here code:
#include <windows.h> #include "urlmon.h" #pragma lib "urlmon.lib" using namespace std; void dwfile(); int _tmain(int argc, _tchar* argv[]) { dwfile (); return 0; } void dwfile () { lpcstr url = ("http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf"); lpcstr fpath = ("c:\\users\\andyy\\desktop\\test\\n3337.pdf"); hresult urldownloadtofile ((null, url, fpath, 0, null)); }
your code not doing error handling, , string handling wrong. use instead:
#include <windows.h> #include "urlmon.h" #pragma lib "urlmon.lib" using namespace std; void dwfile(); int _tmain(int argc, _tchar* argv[]) { dwfile (); return 0; } void dwfile () { lpctstr url = text("http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf"); lpctstr fpath = text("c:\\users\\andyy\\desktop\\test\\n3337.pdf"); hresult hr = urldownloadtofile (null, url, fpath, 0, null); if (failed(hr)) { // ... } /* or more preffered: lpcwstr url = l"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf"; lpcwstr fpath = l"c:\\users\\andyy\\desktop\\test\\n3337.pdf"); hresult hr = urldownloadtofilew (null, url, fpath, 0, null); if (failed(hr)) { // ... } */ }
do note following comment in documentation:
urldownloadtofile returns s_ok even if file cannot created , download canceled. if szfilename parameter contains file path, ensure destination directory exists before calling urldownloadtofile. for best control on download , progress, ibindstatuscallback interface recommended.
Comments
Post a Comment