Программирование в IIS




Пример 5.2


// HelloWorld.cpp : Defines the entry point for //the DLL application.

#include <httpext.h> //for ISAPI classes and structures

// tell the compiler to shut up about using STL #pragma warning(disable:4786) #include <string> //to build response to send back to user using namespace std;

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Name:GetExtensionVersion

In: pVer - Pointer to ISAPI structure HSE_VERSION_INFO.

Out: Returns true if you want IIS to use the extension, otherwise if another value is returned, IIS will not use the extension

Purpose: Called when the extension is loaded into IIS. The member variables of HSE_VERSION_INFO, dwExtensionVersion and lpszExtensionDesc should be filled with the extension version and description.

Other initialization functionality could be called from this function to set up the server to use this extension.

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) { //ISAPI version const DWORD VERSION_NUMBER = 0.9; const char* VERSION_NAME = "Hello World";

pVer->dwExtensionVersion = VERSION_NUMBER;

strncpy( pVer->lpszExtensionDesc, VERSION_NAME, HSE_MAX_EXT_DLL_NAME_LEN);

return TRUE; }

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Name:HttpExtensionProc

In: pECB - pointer to the Extension control block structure

Out: DWORD - HSE status code

Purpose: main entry point for HTTP request

the possible return codes are: HSE_STATUS_SUCCESS - everything worked great HSE_STATUS_SUCCESS_AND_KEEP_CONN - same as HSE_STATUS_SUCCESS since IIS 4 HSE_STATUS_PENDING - wait until effort completed HSE_STATUS_ERROR - sends a 500 error code /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB) { //HTTP headers const char* BASIC_HEADER = "Content-type: text/html\r\n\r\n"; //output values const DWORD BUFFER_LENGTH = 4096; TCHAR szTempBuffer[BUFFER_LENGTH]; DWORD dwBufferSize = BUFFER_LENGTH; string sResponse;

//start our HTML document sResponse = "<HTML><HEAD></HEAD><BODY><P>"; sResponse += "Hi! Hello World"; sResponse += "</P></BODY></HTML>";

// set content-type header strcpy(szTempBuffer, BASIC_HEADER); DWORD dwHeaderSize = strlen(szTempBuffer); pECB->ServerSupportFunction(pECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, NULL, &dwHeaderSize, (LPDWORD) szTempBuffer);

//write value to http response DWORD dwLength=sResponse.length(); pECB->WriteClient( pECB->ConnID, (PVOID)sResponse.c_str(), &dwLength, 0);

//return a success code return HSE_STATUS_SUCCESS; }

Листинг 5.2. Source Code for HelloWorld.cpp

Закрыть окно






Содержание  Назад  Вперед