An example program

Here is a working Windows CGI program which could be the basis of something useful. It was compiled with Microsoft Visual C++ 1.5, though any C or C++ compiler would do. Although some of the Microsoft Foundation Classes might have been useful, you cannot easily use some classes without bringing in the whole caboodle; as most of the classes are to do with displaying information, this seems a bit unnecessary. So this code is just a plain old Windows application.

My GetArgs() routine is no great shakes, but it does split up the passed lpszCmdLine into argc and argv globals - do your own improvements... If there are a wrong number of arguments, or any other errors occur, then LogError() is called which appends an error message to a log file, together with a copy of the given lpszCmdLine.

This example is designed to cope with being called from different links, differentiated by the extra path information which is added to the URL. So I check the Logical Path parameter in the [CGI] section of the CGI data file, and switch accordingly. Whatever happens, the wee message loop has to be run so that httpd can keep up with us.

The program expects to be called with one of two settings for the Logical Path, either "/Comments" or "/Order". For the latter case, HandleOrder() receives user entries from a form which contains Name, Fax, Card, Contact and Address keys, as well as a hidden ProductCode key. The Address key is a TEXTAREA, so TidyMultiLine() is called that newline \r characters are removed. HandleOrder() builds a suitable response HTML page for the user, and calls (an empty) StoreOrder() to file away the order details.

Here is a picture of the response for a correct order.


Return to Web Forms