473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Internet

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
Nov 17 '05 #1
2 958
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

Nov 17 '05 #2
KM wrote:
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
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stefan Mueller | last post by:
I've just installed phpMyAdmin. If I have the line $cfg = 'http://localhost/php/phpmyadmin'; in my config.inc.php I can login to phpMyAdmin without any problems from my local machine. But it's...
12
by: Cliff Wells | last post by:
Hi, I'm writing an application that needs to know if an Internet connection is available. Basically, I want to have something similar to what a lot of email clients have, where the app can work...
1
by: J-miami | last post by:
I am just starting to learn Perl. I had an idea that there should be free open-source Internet Cafe management software for Linux. I searched around online but couldn't find anything. The...
6
by: Matt Hawley | last post by:
I'm facing a problem where I need to verify that my windows forms application has access to the internet before it can do anything. Currently, the only way I can think of is by creating a...
40
by: Mark G. Meyers | last post by:
http://www.savetheinternet.com There is more info and A PETITION at moveon... Easy to sign and give your two cents (and to your own reps in the process)....
0
by: jfranco | last post by:
GANHE DINHEIRO COM A INTERNET E AJUDA MÚTUA! Pode parecer mais uma daquelas falsas notícias que você vê por aí, MAS POR FAVOR LEIA este texto para entender, é muito fácil, simples e funciona!! O...
6
by: =?Utf-8?B?QnNtZW5nZW4=?= | last post by:
I am trying to make sure that the local connection is up. I have presently been using the NetworkChange.NetworkAvailabilityChanged Event for this. Is there a better way to do this? Also, I...
15
by: ingejg | last post by:
I am starting to study internet synchronization, and my head is still spinning since internet is not my forte, however my boss is breathing down my neck at the moment. Our company has only one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.