Hi group
I´m currently trying to put together a small c++ dll that can access a
webpage and write the contens to a local disk (I´m using VS.NET 2003).
It seems that MS has created some nice API´s for accessing internet
pages, and I´m trying something like this:
CInternetSession oSes("Mozilla Firefox");
CStdioFile* oFile = oSes.OpenURL(cURL);
The way I´ve read the msdn, oFile is now a pointer to the whole webpage
and it should be easy to write it to a local disk. Is that correct?. If
so, how do I do it?
Any suggestion or links is most welcome
TIA
Kaare
Rodrigo Corral [MVP] - 10 Jun 2005 16:26 GMT
CInternetSession session;
CStdioFile* pPage = NULL;
CStdioFile File("C:\\temp\\test.html", CFile::modeCreate |
CFile::modeWrite);
const DWORD buffSize = 1024;
BYTE buff[buffSize];
pPage = session.OpenURL("http://www.terra.es");
while (pPage->Read(buff, buffSize) > 0)
{
File.Write(buff, buffSize);
}
delete pPage;
File.Close();
session.Close();

Signature
Un saludo
Rodrigo Corral González [MVP]
FAQ de microsoft.public.es.vc++
http://rcorral.mvps.org
Carl Daniel [VC++ MVP] - 10 Jun 2005 16:39 GMT
> Hi group
>
[quoted text clipped - 11 lines]
>
> Any suggestion or links is most welcome
A complete program to save the contents of an URL to a file.
/// Code follows
#include <windows.h>
#include <tchar.h>
#include <urlmon.h>
#include <stdio.h>
int _tmain(int argc, TCHAR* argv[])
{
if (3 != argc)
{
_tprintf(_T("usage: %0 URL out-file-name"),argv[0]);
return 1;
}
::CoInitialize(0);
TCHAR szFullName[MAX_PATH];
::GetFullPathName(argv[2],MAX_PATH,szFullName,0);
HRESULT hr = ::URLDownloadToFile(
0,
argv[1],
szFullName,
0,
0
);
::CoUninitialize();
if (FAILED(hr))
{
_tprintf(_T("Failed, hr=0x%08x\n"),hr);
return 2;
}
return 0;
}
/// End of Code
-cd