Click to open or copy the PINBALL project files.
The PINBALL sample demonstrates several challenging techniques in the development of an Internet Server Extension that uses MFC. PINBALL provides a simple form that allows users to select the names of their favorite pinball machines. If the user selects one of the listed machines, an image of that machine's backglass artwork is displayed. Users who indicate that they don't see the name of a favorite machine are redirected to a popular Internet site to search for information about the machine.
Install the application on your Web server by copying the Pinball.dll executable file to any directory in your published Web space. Also, copy Tz.gif, Mars.jpg, Cv.gif, and Taf.gif to the directory that contains Pinball.dll.
Once the sample is installed, invoke the sample by executing it from your Web client. If the sample is in the root directory of the Web space on a server named MOOSEBOY
, for example, use the following URL to execute the sample:
http://mooseboy/pinball.dll
The sample will respond with the main form from the extension, which is stored as a resource in the extension's image and sent from the Default
member function in CPinballExtension
.
If you select a pinball game and click Show Me to submit the form, the server will provide a graphic file depicting the artwork on the game's backglass. All of the artwork files show games made by Williams Industries in Chicago.
How the Sample Works
The extension uses CHttpServerContext::TransmitFile to send the file to the client as fast as possible. TransmitFile instructs Windows NT to transmit the file directly from the disk, without performing any double-buffering. On a very high-volume server, this technique can improve response time and scalability significantly. CHttpServerContext::TransmitFile calls CHttpServerContext::ServerSupportFunction with the HSE_REQ_TRANSMIT_FILE command, which actually performs the work. Using HSE_REQ_TRANSMIT_FILE requires some extra work, and TransmitFile does that work.
You will notice that the CPinballExtension::GetImage
command handler is responsible for responding to the form. If any error occurs, the function makes an HTTP response by using the StartContent, WriteTitle, and EndContent members of CHttpServer, like most normal HTML-based extensions.
If the user requests a graphics file that is successfully found and properly transmitted, the command handler function does not make calls to send anything else. Because TransmitFile takes care of sending the headers and the data, no further communication is necessary. The SendJPGFile
and SendGIFFile
functions prepare a part of the header and call SendAFile
to do the rest of the work.
If the user's response indicates no favorite machines are on the form, the extension will redirect the user to the Internet Pinball Database, a popular Internet site for pinball aficionados. The redirection operation isn't complicated: the server simply sends a plain HTML response with a <META> tag that performs the redirection.
This sample demonstrates the following keywords:
CHttpServer::TerminateExtension, CHttpServer::GetExtensionVersion, CHttpServer::StartContent, CHttpServer::WriteTitle, CHttpServer::EndContent, CHttpServerContext::ServerSupportFunction, BEGIN_PARSE_MAP, ON_PARSE_COMMAND, DEFAULT_PARSE_COMMAND, ON_PARSE_COMMAND, ON_PARSE_COMMAND_PARAMS, END_PARSE_MAP