Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

Internet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KM - 10 Jun 2005 08:34 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.