I am trying to find a way to download an .exe file from the internet. I already know how to install it ( I think... ) But I just cant get past the download. I also want it to go right to the C drive and not into a temp folder.
I thought this might happen... I guess I wasn't specific enough. I mean in the c++ code how to lets say, download file abcd.exe from google.com like this
1 2 3 4 5 6 7 8 9 10 11
#include<iostream>
usingnamespace std;
int main ()
{
dload(www.google.com/files/abcd.exe, C:\downloads); //This is where I would download the file
system("C:\downloads\abcd.exe"); //This is where I would run the file
system("PAUSE");
return(0)
}
I know there are probably errors in this but this is just an example and I KNOW dload is not a command but I just put it there to hold the place if you know what I mean
You can use Wget... Either install it and use it in a system(), or take a look at the source code and figure out how it retrives files... (I don't know if it's in C/C++ though)
Wget and it's source code are available here: http://gnuwin32.sourceforge.net/packages/wget.htm
On Linux you would use the socket library. On windows, you would use the winsock library or for maximum c00lness you can use the UNIX style socket library and compile with Cygwin when you want a windows executable.
Downloading a file with the socket library is really quite simple.
The code that you gave will not compile in dev C++. It gives the following errors:
1 2 3 4 5 6 7 8 9
#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;
}
Unlikely. You probably need a library (say, "liburlmon.a" or "urlmon.lib") as well, and given that it's most likely distributed in the precompiled format, it won't be compatible with MinGW.
I am in the process of downloading VC++ Express and I will post my results, but where (If I need it) can I find the urlmon library?
Thanks,
Adam
*Edit*
P.S. Chris name you were right. I copied a urlmon.h (not from VC++) into dev c++'s include directory and it did not compile with out about a dozen more header files that I didnt have.