
Welcome to WinHttpWrappers, a set of MFC 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: CWinHttpHandle, CWinHttpSession, CWinHttpConnection, CWinHttpRequest, CAsyncWinHttpDownloader & CSyncWinHttpDownloader.
CWinHttpHandle 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.
CWinHttpSession provides encapsulation of a WinHttp session HINTERNET handle. It provides an "Initialize" method which encapsulates the WinHttpOpen API.
CWinHttpConnection provides encapsulation of a WinHttp connection HINTERNET handle. It provides an "Initialize" method which encapsulates the WinHttpConnect API.
CWinHttpRequest 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.
CAsyncWinHttpDownloader which derives from CWinHttpRequest 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 CSyncWinHttpDownloader which derives from CAsyncWinHttpDownloader is provided. This class provides a high level wrapping of a synchronous WinHttp request.
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 "CDownloadFileWinHttpRequest" class. It also demonstrates cancelling of pending requests as well as reporting the various callbacks which occur during the download.
V1.0 (29 May 2011)
V1.01 (30 May 2011)
V1.02 (1 August 2011)