Naughter Software Logo

WinHTTPWrappers v1.12 A set of C++ classes to encapsulate WinHTTP

Welcome to WinHttpWrappers, a set of C++ classes to encapsulate WinHTTP and especially its asynchronous support. The classes are based on the MSDN Magazine article about WinHTTP by Kenny Kerr at http://msdn.microsoft.com/en-gb/magazine/cc716528.aspx. You should read this article to get a better understanding on how to properly use WinHTTP (especially when in asynchronous mode). Coming back to my classes then should make more sense<gg>.

 

The classes provided are: WinHTTPWrappers::CHandle, WinHTTPWrappers::CSession, WinHTTPWrappers::CConnection, WinHTTPWrappers::CRequest, WinHTTPWrappers::CAsyncDownloader & WinHTTPWrappers::CSyncDownloader.

CHandle provides a class based encapsulation of a HINTERNET handle and various WinHTTP methods which work on any HINTERNET type handle. It also provides a prebuilt virtual callback method called "OnCallback" which derived classes can customize.

CSession provides encapsulation of a WinHTTP session HINTERNET handle. It provides an "Initialize" method which encapsulates the WinHttpOpen API.

CConnection provides encapsulation of a WinHTTP connection HINTERNET handle. It provides an "Initialize" method which encapsulates the WinHttpConnect API.

CRequest provides encapsulation of a WinHTTP request HINTERNET handle. It provides an "Initialize" method which encapsulates the WinHttpOpenRequest API. It also encapsulates all the WinHTTP API calls which take a request handle such as WinHttpAddRequestHeaders, WinHttpQueryHeaders, WinHttpReadData, WinHttpQueryAuthSchemes etc etc.

CAsyncDownloader which derives from CRequest which provides for a high level wrapping of an asynchronous WinHTTP request. It supports sending request bodies from a file or from an in-memory array. It also supports downloading to a file or to an in-memory array. Internally this class looks after a memory buffer and file for downloading the request into. It also supports various authentication schemes and bandwidth throttling. It also implements proper thread protection of these values to ensure correct operation when WinHTTP is used in asynchronous mode. It also provides a number of virtual methods, including OnReadData, OnWriteData, GetHeaders, GetContentLength, DoAuthentication, ChooseAuthScheme, On407Response, On401Response and OnCallbackComplete which provide various notifications during the lifetime of a WinHTTP download request.

Finally CSyncDownloader which derives from CAsyncDownloader is provided. This class provides a high level wrapping of a synchronous WinHTTP request.

 

 

Features

 

The enclosed zip file contains the WinHTTPWrappers source code and a simple VC 2008 dialog based application which demonstrates the classes using a simply asynchronous download of a HTTP page to a local file using the "CMyDownloadFileWinHTTPRequest" class. It also demonstrates cancelling of pending requests as well as reporting the various callbacks which occur during the download.

 

Copyright

 

Updates

V1.0 (29 May 2011)

V1.01 (30 May 2011)

V1.02 (1 August 2011)

V1.03 (30 March 2013)

V1.04 (1 December 2013)

V1.05 (8 June 2014)

V1.06 (8 March 2015)

V1.07 (11 March 2015)

V1.08 (14 June 2015)

V1.09 (7 November 2015)

V1.10 (6 March 2016)

V1.11 (16 April 2017)

V1.12 (27 April 2017)