Click here to Skip to main content
13,860,468 members
Click here to Skip to main content
Add your own
alternative version


29 bookmarked
Posted 12 Aug 2005


, 12 Aug 2005
Rate this:
Please Sign up or sign in to vote.
Internet classes for WTL developers.


In this article, I'll introduce some wrapper classes I've wrote to use INET under WTL. To make things simple, the code uses C++ exceptions, so there is no need to check the result code of every function call.


All handles inherit from CInternetHandle, so there is no need to destroy them manually.

To start using INET, you first need to create a session. This can be done by creating a CInternetSession object. You can specify the user-agent in the constructor, or leave it blank (in that case, the code will use your application name as the user-agent string).

CInternetSession Session(_T("Test Application"));


Currently there are two types of connections: HTTP and FTP. To create a connection, you simply construct an object with the server parameters.

CHttpConnection Connection1(Session,_T(""));
CFtpConnection Connection2(Session,_T(""));


All internet files inherit from CInternetFile. In addition, there are three special files: HTTP/HTTPS and FTP. You can create a file object via an already made connection, or create a new one via a session object.

BYTE Buffer[4096];

CHttpFile File1(Connection1,_T("GET"),_T("/"));
for (DWORD dwRead1;dwRead1=File1.Read(Buffer,sizeof(Buffer)););

CHttpFile File2(Session,_T(""));
for (DWORD dwRead2;dwRead2=File2.Read(Buffer,sizeof(Buffer)););

When reading from files, there is also a special option, allowing you to time the download, as well as limit it to a certain download speed. You can do it by using the CInternetFile::CInfo class.

BYTE Buffer[4096];
CHttpFile File3(Session,_T(""));
CInternetFile::CInfo Info(File3);
for (DWORD dwRead3;dwRead3=File3.Read(Buffer,sizeof(Buffer),Info);)
   // Info.GetTimeLeft() = Seconds left for download


When an error occurs, the code throws an exception (CInternetException). You can get the error message with the GetErrorMessage function.

  CInternetSession Session;
  CHttpFile File(Session,_T(""));
catch(CInternetException& err)

Bugs & Limitations

I've tried to implement a callback mechanism, but it still has some problems. Avoid using it for now. In addition, since I haven't had any real need for gopher, I never put it inside my code. You are welcome to add it if you need it. I'm using that code in my projects, but it may still contain some bugs. If you find any problem, please notify me.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Gilad Novik
Web Developer
Israel Israel
Gilad was born accidently to a pair of old lesbians. His childhood was full of vibrators and drugs. Married without kids. Has 14 grandsons around the world, 4 crocodiles, 2 mushrooms and a green alien living behind the refrigerator.

Hobbies: Watching hardcore porn, sculpturing with snot, skydiving from stairs.

Check my Homepage for additional resources.

Quote: "There's always one more bug"

You may also be interested in...

Comments and Discussions

GeneralSmaller bug Pin
simonchen.net13-Feb-11 4:01
membersimonchen.net13-Feb-11 4:01 
GeneralAccessing REST web services Pin
kapil_moondra9-Mar-10 23:10
memberkapil_moondra9-Mar-10 23:10 
Generalmfc library Pin
monsieur_jj11-May-08 23:14
membermonsieur_jj11-May-08 23:14 
General2 small fixes Pin
Mike Melnikov8-Sep-05 22:13
memberMike Melnikov8-Sep-05 22:13 
GeneralInteresting Bio Pin
NormDroid13-Aug-05 2:04
professionalNormDroid13-Aug-05 2:04 
Generalnew wheels Pin
gnk12-Aug-05 22:02
membergnk12-Aug-05 22:02 
GeneralRe: new wheels Pin
Gilad Novik13-Aug-05 7:10
memberGilad Novik13-Aug-05 7:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190214.1 | Last Updated 12 Aug 2005
Article Copyright 2005 by Gilad Novik
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid