LISTING 2: Simple ISAPI Extension
Note: The symbol * signals a wrapped line.
/*
Simple ISAPI Extension: Hello, I must be going!
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "httpext.h"
BOOL WINAPI DllMain(IN HINSTANCE hinstDll, IN DWORD dwReason, IN LPVOID
* lpvContext)
{
switch( dwReason ) {
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return(TRUE);
}
BOOL WINAPI GetExtensionVersion(OUT HSE_VERSION_INFO * pVer)
{
pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR,
HSE_VERSION_MAJOR );
strcpy( pVer->lpszExtensionDesc,"IIS Simple ISAPI Extension" );
return TRUE;
}
DWORD WINAPI HttpExtensionProc(IN EXTENSION_CONTROL_BLOCK * pECB)
{
static char szMessage[] =
"<html>\r\n"
"<head>\r\n"
"<title>Hello World</title>\r\n"
"</head>\r\n\r\n"
"<body>\r\n"
"<p>Hello, I must be going!</p>\r\n"
"</body>\r\n"
"</html>\r\n";
HSE_SEND_HEADER_EX_INFO HeaderExInfo;
HeaderExInfo.pszStatus = "200 OK";
HeaderExInfo.pszHeader = "Content-type: text/html\r\n\r\n";
HeaderExInfo.cchStatus = strlen( HeaderExInfo.pszStatus );
HeaderExInfo.cchHeader = strlen( HeaderExInfo.pszHeader );
HeaderExInfo.fKeepConn = FALSE;
//
// send headers using IIS-provided callback
// (note - if we needed to keep connection open,
// we would set fKeepConn to TRUE *and* we would
// need to provide correct Content-Length: header)
pECB->ServerSupportFunction(
pECB->ConnID,
HSE_REQ_SEND_RESPONSE_HEADER_EX,
&HeaderExInfo,
NULL,
NULL
);
//
// Calculate length of string to output to client
//
DWORD dwBytesToWrite = strlen( szMessage );
//
// send text using IIS-provided callback
//
pECB->WriteClient( pECB->ConnID, szMessage, &dwBytesToWrite, 0 );
//
// Indicate that the call to HttpExtensionProc was successful
//
return HSE_STATUS_SUCCESS;
}
BOOL WINAPI TerminateExtension(IN DWORD dwFlags)
{
return TRUE;
}