Converting Existing CGI Scripts to ISAPI Extensions
This section explains the basic requirements for converting existing CGI script-executable files to ISAPI extension DLLs. As with other DLLs, Web server applications must be thread-safe. More than one client will be executing the same function at the same time, so the code should follow safety procedures in modifying a global or static variable.
You can keep your ISAPI extension thread-safe by using appropriate synchronization techniques, such as creating critical sections and semaphores. For additional information on writing thread-safe DLLs, see the documentation in the Platform SDK and in the Microsoft Development Library.
There are several structural differences between an ISAPI extension and a CGI executable file. An ISAPI extension:
- Receives most of its data through the lpbData member of the EXTENSION_CONTROL_BLOCK structure, as opposed to reading it from the standard input (STDIN) handle for the process. For any additional data, the extension uses the ReadClient callback function.
- Sends data back to the client with the WriteClient callback function instead of writing to the STDOUT (standard output) handle for the process.
- Accesses common CGI variables through the EXTENSION_CONTROL_BLOCK structure. For other variables, it calls GetServerVariable. In a CGI executable file, these are retrieved from the environment table by using getenv.
- Specifies completion status by either sending the header directly using the WriteClient callback function, or calls the HSE_REQ_SEND_RESPONSE_HEADER_EX ServerSupportFunction, instead of sending a "Status: NNN xxxxx..." to STDOUT.
- Redirects requests with a Location: or URL: header; instead of writing the header to STDOUT, use the HSE_REQ_SEND_URL if the URL is local. However, if the URL is remote or unknown, HSE_REQ_SEND_URL_REDIRECT_RESP in the ServerSupportFunction callback function should be used.