A Sip From The Firehose: Monday, September 30, 1996

By: David Intersimone

Abstract: Make Big Bucks writing Web Server extension DLLs— A few strcats is all you need!

Monday, September 30, 1996
Scotts Valley, CA

Make Big Bucks writing Web Server extension DLLs—
A few strcats is all you need!

With all the hype about the Internet and how much money programmers can make setting up web sites for companies who can't do it themselves, I wanted to see what it takes to extend the Microsoft Internet Information Server (IIS). After reading an HTML document on Microsoft's web site, I realized that programmers are charging a lot for such simple programming. What does it take to build extension DLLs for IIS? With the Information Server Application Programming Interface (ISAPI), a beginning computer science student in college can easily build a DLL and charge large dollars per hour for the effort. With Delphi, Borland C++ or any other developer tool that can compile and link DLLs for Windows NT you can do it too and be on the road to vast wealth as an Internet Server programmer. Here's how!

First, read the Internet Server API Overview document on Microsoft's web site and the Internet Server API Reference document. These documents will explain what ISAPI is, what you can build with the API, and how it compares to the Common Gateway Interface (CGI) standard for web server programming. Basically the difference is CGI uses and EXE file and ISAPI programming uses a DLL. CGI executables run as a separate process, ISAPI DLLs run in the same process as the IIS gaining several benefits including performance.

In this weeks Sip I will show you how to write a simple ISAPI DLL in C++. For more information about using Delphi for Internet programming check our the the paper by Charlie Calvert, a member of the Borland Developer Relations department, that was presented at the Seventh Annual Borland Developers Conference last July that showed how you can use Delphi and the Internet to build ISAPI DLLs.

Second, make sure you have the httpext.h header file (available as part of Microsoft's ActiveX SDK). This header file contains the defines, typedefs and function prototypes for building ISAPI DLLs. The key structure involved in ISAPI programming is the Extension Control Block (ECB). The ECB contains the parameters that were included (if there were any) with the URL, IIS functions you can call , bytes sent by the client, the content type from the client and other information.

Third, write a simple ISAPI extension DLL you have to provide two functions: GetExtensionVersion and HttpExtensionProc. When the IIS sees a DLL as part of the URL, the web server loads the DLL into memory and calls the GetExtensionVersion function to determine which version of ISAPI you are using and then calls the HttpExtensionProc that does the work required for your application. The ISAPI1.CPP source code shows how to echo the parameter string back the client browser or program. The program is nothing but a series of strcpy and strcat function calls. Of course the complexity of the ISAPI DLL depends on your application. Compile and link the source code to build the DLL. Copy it over to your IIS in the directory where you place your extension DLLs. (Note: if you've already tried the DLL it is probably still in memory. You will need to stop the web server to release the DLL and then start the web server again. Use the IIS manager application to start and stop it). I have also included the ISAPI1.DEF file that defines the exported functions defined in the DLL.

// Simple parameter ISAPI extension DLL.  Echoes the parameter string back to the client.
#include <windows.h>
#include "httpext.h"
#include <string.h>
#include <stdio.h>

// GetExtensionVersion callback definition
BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) {
  strcpy(pVer->lpszExtensionDesc,"Simple Parameter ISAPI DLL");
  return (TRUE);   // I can't imagine how this function can return anything but true

//HttpExtensionProc callback definition
  char HtmlString[500];
  char FinalString[1024];
  DWORD FinalStringLength;

  char *HtmlOpen = "<HTML>";
  char *HtmlClose = "</HTML>";
  char *MyTitle =
   "<HEAD><TITLE>Borland C++ Simple Parameter ISAPI Extension DLL Result Document</TITLE></HEAD>";
  char *MyHtmlBodyOpen = "<BODY><H1>ISAPI1 Parameter was: </H1>";
  char *MyHtmlBodyClose = "<BR></BODY>";
  char *IsapiLogText = "ISAPI1 - Simple Parameter BC++ ISAPI Extension DLL";

  pECB->dwHttpStatusCode = 200;   // Code 200 says that the request completed successfully

  // build the HTML result string

  // if there is a parameter string echo it back
    strcat(HtmlString,"*** NO PARAMETER GIVEN ***");


  //  Build the final result string to be sent back to the browser.
  //  The string contains the HTTP protocol version number (HTTP 1.0)
  //    and the Server status code of 200 for successful operation.
    "HTTP/1.0 200 OKnContent-Type: text/htmlnContent-Length: %dnContent:nn %s",
    strlen(HtmlString), &HtmlString);

  //  get the final length of the whole string - HTTP header + the generated HTML
  FinalStringLength = lstrlen(FinalString);

  //  use the ECB to call WriteClient and pass the final string and length
  pECB->WriteClient(pECB->ConnID, FinalString, &FinalStringLength, 0);

  return (HSE_STATUS_SUCCESS);   // return a successful status back to IIS


Fourth, create a sample HTML document, place it on your IIS and access it from your favorite browser. The HTML should look something like:

<TITLE>My Home Page</TITLE>
<H1>My Home Page Documents</H1>
This is the home page for my home computer.
<A HREF="http://www.borland.com/scripts/mystuff/isapi1.dll?HelloWorld">ISAPI One</A><BR>

You can now write your way to untold riches with a few lines of code, some strcpys and strcats, and of course a little programming magic thrown in.

Good luck with your ISAPI programming.

David I

Server Response from: ETNASC03