Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting a webpage to a file

Status
Not open for further replies.

thegame8311

Technical User
Jan 6, 2012
133
US
I have seen many ways, but strictly I am using visual c++ not visual studio, I have seen URLDownloadToFile, wget and curl but I can't get any of them to work, here is my code:

Code:
#include "stdafx.h"
#include <urlmon.h>
#include <iostream>
#include <tchar.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    HRESULT hr = URLDownloadToFile(NULL, _T("[URL unfurl="true"]http://www.nfl.com"),[/URL] _T("test2.html"), 0, NULL);
    cout << "hi" << endl;
    system("PAUSE");
    return 0;
}
 
Alas, "can't get any of them to work" is not a question.
What's is the problem with your code?

Look at working (?) code example or ask true question:

Are you sure that is "a string value that contains the URL to download" (see MSDN URLDownloadToFile article)?
It's doubtful...
 
Sorry, here is the error that returns when I try to run that code

Code:
error LNK2019: unresolved external symbol _URLDownloadToFileW@20 referenced in function _wmain


Also if I use the code from the link provided above i get this:

Code:
error C2664: 'URLDownloadToFileW' : cannot convert parameter 2 from 'const char [29]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
 
The 1st problem:
Add urlmon.lib to your project. For example, see #pragma comment(lib... line in the code from the link above.

The 2nd one:
The code from the link above is not intended for UNICODE (see non-Unicode text literals). Set non-Unicode mode in your project or add L prefix to all text literals in the code.
 
ok, i got the first one to work, but now I am trying to use a variable as the second parameter.

Code:
HRESULT hr = URLDownloadToFile(NULL, plink, _T("test2.txt"), 0, NULL);

the variable is getting filled from a file and it does have a value
 
You don't present any code filled link memory accessed via plink pointer. We can't see this memory object and/or plink variable declaration and definition. We know nothing about this call 2nd argument or this call return value...

May be it's a good time to turn for help of telepathic debugging service?
 
well i found out it was actual because I did not change from 'unicode' to 'Not Set'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top