Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


December 1996

MFC ISAPI Extensions Hit Light Speed, Part 2


RSS
Subscribe to Windows IT Pro | See More Internet Server API (ISAPI) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

MFC Extensions Hit Light Speed

If you need Web speed, you need Internet Server API (ISAPI) Extensions. An ISAPI Extension DLL lets you replace the slow and resource-hogging Common Gateway Interface (CGI) for such purposes as processing fill-in forms. As Part 1 of this series (October 1996) explained, CGI scripts and executables run in a separate process space. ISAPI runs in the same process space as the HTTP server, so ISAPI allows faster startup and communication than other types of CGI. In addition to faster connections, ISAPI increases the speed of Microsoft's Internet Information Server (IIS) because with ISAPI, IIS can use threading to process more than one request at a time.

To create an ISAPI Extension, you can start from scratch or simply use the Microsoft Foundation Class (MFC) ISAPI Wizard. If you choose MFC wizardry, you'll finish very quickly. In addition, you can use the methodology this article presents to create functional ISAPI Extension CGI replacements quickly and consistently. You'll need IIS or another ISAPI HTTP server installed on a Windows NT server, Microsoft Visual C++ 4.1 or later, and a CGI-compatible Web browser, such as Internet Explorer or Netscape.

Part 1 showed how to create an ISAPI Extension that responds to a fill-in form. The code did not do anything except display a default message. This article shows how to modify an ISAPI Extension that the MFC Wizard generates. I cover the Wizard-generated ISAPI Extension additions you need for the example form in Part 1. The additions let you initially display the Comment and Suggestion form shown in Screen 1 as the default and display the second page with the return email address and link to the all-records page. The HTML that produces the Comment and Suggestion fill-in form is in Listing 1.

ISAPI Wizardry Revisited
After you prepare the HTML for the fill-in form, as in Listing 1, create an ISAPI Extension with the Visual C++ ISAPI Extension Wizard. The Wizard creates an ISAPI Extension with the entire MFC ISAPI framework, but little else. We'll extend this framework to display the Comment and Suggestion form shown in Screen 1 and handle the CGI request generated when a user enters a comment (as you see in Screen 2) and clicks Send on the form.

To generate the initial ISAPI Wizard, start Visual C++, select the File menu, and click New. Double-click the Project Workspace option. The New Project Workspace dialog appears. From the Type list, select ISAPI Extension Wizard. In the Name text box, type comment as the name of your project. Click Create to pull up the ISAPI Extension Wizard - Step 1 of 1 dialog you see in Screen 3. Select Generate a Server Extension object to specify that you want an MFC-generated class--an ISAPI Extension--to handle ISAPI Extension, or CGI, requests. Click Finish to display the New Project Information dialog. Click OK to complete the task.

Modifying the MFC Wizard ISAPI Extension
So let's walk through a simple, standard methodology to finish the ISAPI Extension created in Part 1 of this series. The ISAPI Extension will display the Comment and Suggestion form for a URL that points to the ISAPI Extension with no arguments (http://spain.winntmag.com/comment.dll?). You must add a method, postComments, to the class created by the MFC Wizard, CCommentExtension, to process the values passed to the ISAPI Extension DLL when someone selects Send on this form. Listing 2 shows the prototype for the CCommentExtension::postComments method.

The MFC ISAPI framework uses a CGI request-to-method parse map to determine which method of the CCommentExtension class to call and how to map the CGI-request named values to the method's parameters. To set up the parse map for the comment and suggestion form, add the two lines in Listing 3 to the parse map at the top of the comment.cpp file. The parse map, an MFC addition, maps the parameters of a specific method of the CComment Extension class(e.g., LPTSTR whoIsIt) to the named values (e.g., INPUT NAME= "WHOISIT") sent from the fill-in form. The first parse map entry line, ON_ PARSE_COMMAND macro, specifies the method name (postComments), the class (CCommentExtension), and the data type of each of the class method's parameters. The second line specifies the named values passed from the form to the ISAPI Extension. These values correspond to the class method's parameters specified in the first macro. For example, the first parameter for the postComments method is LPTSTRwhoIsIt. In the first macro, ITS_PSTR (a string type) is the type for LPTSTR whoIsIt. In the second macro, WHOISIT is the named value associated with this parameter. MFC uses this parse map to associate incoming form data (named values) with parameters to pass to class methods.

Before we add the postComments class method, we need to store and read long strings of HTML code. More specifically, we want to store as a resource the initial form and portions of the results page that the postComments method generates. Visual C++ 4.1 includes the WWW QUOTE example, which illustrates how to create a new custom resource type for HTML code. To simplify the process of loading long HTML strings from resources, we'll borrow some code and techniques highlighted in the WWW QUOTE example.

First, incorporate two class methods from this example into your ISAPI Extension class: Copy the WritePage Title and LoadLongResource methods from the WWWQUOTE example and change the class names from CWWWQuote to CCommentExtension to match your class name in the method declarations and definitions. You'll use this codelater in this example for reading whole HTML pages from custom HTML resources. You can put this code into a separate file and call it helper.cpp for future use in other ISAPI Extension projects.

   Previous  [1]  2  Next 


Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...

PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...

Escape From Yesterworld

Kevin points you to the funniest SQL Server website ever! ...


Related Articles MFC ISAPI Extensions Hit Light Speed, Part 1

Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing