Windows with C++: Asynchronous WinHTTP

My latest Windows with C++ column in the August 2008 issue of MSDN Magazine is now online: Asynchronous WinHTTP.

This article had a bit of a rough time in the editing process and it’s not quite as polished as I would like. Nevertheless it’s still a good read and should give you a good starting point for building high performance and highly responsive HTTP client applications.

It was also heavily edited to meet the limited space requirements of print publication and some sections were dropped. One of them was a section on the positioning of WinHTTP compared to WinInet:

Veteran Windows developers may remember the Windows Internet (WinInet) API that has been around for years.  WinInet still provides a number of unique features such as support for FTP, credential caching, and user interface support. On the other hand it is not an ideal solution for service applications. It is also not suitable if your application needs to manage its own credentials, you don’t want to introduce user interface prompts, or don’t want to rely on Internet Explorer for proxy configuration.

The first paragraph in the Request Cancellation section was also edited to the point where it is incorrect and quite misleading. It should read:

WinHTTP provides a less error-prone model for asynchronous completion when compared to WinInet since your application is always notified of the completion of an operation through the callback function. On the hand, since worker threads are used to execute the callback function, cancelling a request does require some attention to detail.

Finally the section entitled Determining Proxy Settings was cut entirely from the print issue but is available as a sidebar in the online issue, although the associated screenshot was omitted.

Phew. Hopefully these minor issues will be straightened out eventually.

If you’re looking for one of my previous articles here is a complete list of them for you to browse through.

Produce the highest quality screenshots with the least amount of effort! Use Window Clippings.

4 Comments

  • Good stuff, I'm glad some people are still doing plain c++ without any frameworks. Thank you Kenny!

  • I sent you an email, concerning the failure of the article to to provide a clear statement that the callback function is called in the context of a different thread, and its failure to explain the implications of this (need for synchronization etc).

  • malachy: I didn't get your email (kennykerr@gmail.com). The article does in fact mention that the notifications are handled by worker threads (the thread pool). I had very limited space to cover quite a large topic. As far as synchronization goes, it's very application specific thus hard to cover generally. Many applications treat WinHTTP with state transitions so no specific synchronization is needed. The only area where you absolutely need to handle it specifically is during cancellation but how that is handled is also very application specific. I did mention the need for this in the section on request cancellation in the article. For example a good approach is to post all notifications to your application's window message loop which can then provide implicit synchronization.

    Hope that helps.

  • malachy: Thanks for the feedback!

Comments have been disabled for this content.