Internet

  • Thread starter Thread starter KM
  • Start date Start date
K

KM

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
 
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();


--
Un saludo
Rodrigo Corral González [MVP]

FAQ de microsoft.public.es.vc++
http://rcorral.mvps.org
 
KM said:
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

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
 
Back
Top