Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


getting a webpage to a file

getting a webpage to a file

getting a webpage to a file

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:


#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("http://www.nfl.com"), _T("test2.html"), 0, NULL);
    cout << "hi" << endl;
    return 0;

RE: getting a webpage to a file

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 www.nfl.com is "a string value that contains the URL to download" (see MSDN URLDownloadToFile article)?
It's doubtful...

RE: getting a webpage to a file

Sorry, here is the error that returns when I try to run that 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:


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

RE: getting a webpage to a file

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.

RE: getting a webpage to a file

ok, i got the first one to work, but now I am trying to use a variable as the second parameter.


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

the variable is getting filled from a file and it does have a value

RE: getting a webpage to a file

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?

RE: getting a webpage to a file

well i found out it was actual because I did not change from 'unicode' to 'Not Set'

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close