httpd runs your program with three or four parameters, namely the CGI data file path, the content-file path, the output file path, and optionally a string with any query given with the URL (ie after a question mark). The CGI data file and the output file are usually the main items of interest. If the returned data is huge, then you may need to refer to the actual content file; this is in the usual encoded form (eg Name=Chris&Pound=Sign+%A3). The query string is also copied into the CGI data file, so you may as well pick it up there.
As before, your task is simply to inspect the input data and write your results to the output file. There is a sting in the tail however; if you just roar through this job then httpd loses sync with you, so you have got to add in a wee message loop with a timer delay.
The other obvious point to make at this stage is that programs should be designed to run to completion. If you detect an error, then do not just bung up a MessageBox - this will stop everything dead. I write any errors to the end of a log file. If you don't return any valid output then httpd or your browser will usually come up with a suitable message.
My first cut C++ program simply wrote to output file and stopped - httpd just hung up. My second attempt has a small message loop which issued a WM_CLOSE to itself straight away - httpd still hung up, although Rob thought that this should work. My final working code sets a small timer delay, and only issues the WM_CLOSE when the timer has tolled its bell - so far this has been solid.
All this code is in DoTinyMessageLoop() and its associated WndProc() in a working Windows program. Note that the normal calls to ShowWindow() and UpdateWindow() are not necessary, especially as httpd runs WinMain() with nCmdShow set to SW_SHOWMINNOACTIVE.