XmlHttpRequest


lightbulb_3.png

The most common interface for fetching external web pages is XMLHTTPRequest. Working how to use this in C++ on windows took me some time and experimentation

The first place to look is Sven Groot's post on using the IXMLHTTPRequest object asynchronously in C++. He explains exactly how to use that object's callback from C++, with a code example. The official documentation has no explanation of how to do this, so Sven's example is a life-saver.

Before that example was available, I wrote my own class that implemented the interface. I started off using the old WinInet library to perform the network operations, but that proved to be very prone to crashing when I called it in a multi-threaded app. For PeteSearch I ended up using a custom class based on WinHttp instead, called CPeteHttpRequest. This is available as part of a standalone sample here.