#include <tchar.h>
#include <urlmon.h> //"urlmon.h: No such file or directory found"
#pragma comment(lib, "urlmon.lib")
int main()
{
HRESULT hr = URLDownloadToFile ( NULL, _T("your web page"), _T("c:/web_page.html"), 0, NULL );
//"HRESULT undeclared (first use this function)" and "expected `;' before "hr"
return 0;
}
This is what I made, I added a string that I want to be able to edit with cin as I run the program. But for some reason this does not work. Also added the file location as a string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <string>
#include <string.h>
#include <tchar.h>
#include <urlmon.h> //"urlmon.h: No such file or directory found"
#pragma comment(lib, "urlmon.lib")
usingnamespace std;
int main()
{
string location = "C:/";
string url = "test with a url here";
cout << "downloading Piriform CCleaner...";
HRESULT hr = URLDownloadToFile ( NULL, _T(url), _T(location), 0, NULL );
cout << "Done!" << endl;
}
Errors I get
1 2
1>c:\users\thomas\documents\visual studio 2010\projects\dload\dload\main.cpp(13): error C2664: 'URLDownloadToFileA' : cannot convert parameter 2 from 'std::string' to 'LPCSTR'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
I agree with Fransje... That bit in the middle looks quite clearly like Windows style programming which is all written in C, not C++...
All you have todo is convert your strings by appending .c_str() to the end of the name (you can do this in the function call). HRESULT hr = URLDownloadToFile(NULL, _T(url.c_str()), _T(location.c_str()), 0, NULL);