Retrieval Of Files From The Internet

A

alphaLaura

Hi all,

I recently posted this topic on the Microsoft VC group, but I still
can't get my program working fluidly. As part of my work experience, I
need to write a program which downloads the content of a webpage and
saves it into some file on my computer. I have a program which -does-
work despite giving errors at runtime. Looks like this -

++++++++++++++++++++++++++++++++++++++++++++++++++
#include "stdafx.h"
#include <Urlmon.h>
#include <windows.h>

// fetchMET.cpp : Defines the entry point for the console application.
//

typedef void (*Funk)(LPVOID,char*,char*,int,int);

bool Download(char* URL, char* File_Name)
{
HINSTANCE Dll_Handle = LoadLibrary(_T("Urlmon.dll"));
if (Dll_Handle == NULL) return FALSE;
Funk DnLd = (Funk)GetProcAddress(Dll_Handle,"URLDownloadToFileA");
if (DnLd == NULL) return FALSE;
DnLd(0,URL,File_Name,0,0);
FreeLibrary(Dll_Handle);
return TRUE;
}

int main(int argc, char *argv[])
{
Download("http://weather.uwyo.edu/cgi-bin/sounding?
region=europe&TYPE=TEXT
%3ALIST&YEAR=2007&MONTH=07&FROM=1100&TO=1112&STNM=03953", "wx.txt");
return 0;
}
++++++++++++++++++++++++++++++++++++++++++++++++++

I originally wanted to used the URLDownloadToFile() function but that
also gave me numerous problems. The program for that was very basic
and looked like...

++++++++++++++++++++++++++++++++++++++++++++++++++

#include "stdafx.h"
#include <iostream>
#include <Urlmon.lib>
#include <Urlmon.h>


int main()
{
long int returnValue = 0;
LPCTSTR URL = _T("ftp://tgftp.nws.noaa.gov/data/observations/metar/
stations/EICK.TXT");
LPCTSTR FILENAME = _T("c:\\wx.txt");

returnValue = URLDownloadToFile(NULL, URL, FILENAME, 0, NULL);

return 0;
}

++++++++++++++++++++++++++++++++++++++++++++++++++

I'm just wondering if anybody who has worked on the same problem has
any advice or solutions? Both methods are not working so, any help
would be wonderful!

Laura
 
M

moreteavicar

Hi all,

I recently posted this topic on the Microsoft VC group, but I still
can't get my program working fluidly. As part of my work experience, I
need to write a program which downloads the content of a webpage and
saves it into some file on my computer. I have a program which -does-
work despite giving errors at runtime. Looks like this -

++++++++++++++++++++++++++++++++++++++++++++++++++
#include "stdafx.h"
#include <Urlmon.h>
#include <windows.h>

// fetchMET.cpp : Defines the entry point for the console application.
//

typedef void (*Funk)(LPVOID,char*,char*,int,int);

bool Download(char* URL, char* File_Name)
{
HINSTANCE Dll_Handle = LoadLibrary(_T("Urlmon.dll"));
if (Dll_Handle == NULL) return FALSE;
Funk DnLd = (Funk)GetProcAddress(Dll_Handle,"URLDownloadToFileA");
if (DnLd == NULL) return FALSE;
DnLd(0,URL,File_Name,0,0);
FreeLibrary(Dll_Handle);
return TRUE;

}

int main(int argc, char *argv[])
{
Download("http://weather.uwyo.edu/cgi-bin/sounding?
region=europe&TYPE=TEXT
%3ALIST&YEAR=2007&MONTH=07&FROM=1100&TO=1112&STNM=03953", "wx.txt");
return 0;}

++++++++++++++++++++++++++++++++++++++++++++++++++

I originally wanted to used the URLDownloadToFile() function but that
also gave me numerous problems. The program for that was very basic
and looked like...

++++++++++++++++++++++++++++++++++++++++++++++++++

#include "stdafx.h"
#include <iostream>
#include <Urlmon.lib>
#include <Urlmon.h>

int main()
{
long int returnValue = 0;
LPCTSTR URL = _T("ftp://tgftp.nws.noaa.gov/data/observations/metar/
stations/EICK.TXT");
LPCTSTR FILENAME = _T("c:\\wx.txt");

returnValue = URLDownloadToFile(NULL, URL, FILENAME, 0, NULL);

return 0;

}

++++++++++++++++++++++++++++++++++++++++++++++++++

I'm just wondering if anybody who has worked on the same problem has
any advice or solutions? Both methods are not working so, any help
would be wonderful!

Laura

Hi Laura, in your first example, I think you should use lower case in
urlmon.dll, also I don't think you need #include "stdafx.h" and
#include <urlmon.h> (unless they're for something else in the program
you're writing).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top