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.
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.
for (DWORD dwRead1;dwRead1=File1.Read(Buffer,sizeof(Buffer)););
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
for (DWORD dwRead3;dwRead3=File3.Read(Buffer,sizeof(Buffer),Info);)
When an error occurs, the code throws an exception (
CInternetException). You can get the error message with the
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.