home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / Simple.cpp1 < prev    next >
Text File  |  1997-10-25  |  4KB  |  213 lines

  1. /*++
  2.  
  3. Copyright (c) 1997  Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     Simple.cpp
  8.  
  9. Abstract:
  10.  
  11.     This module shows the basic functions needed for ISAPI extension
  12.  
  13. --*/
  14. #define WIN32_LEAN_AND_MEAN
  15. #include <windows.h>
  16. #include <httpext.h>
  17.  
  18.  
  19.  
  20. BOOL WINAPI 
  21. DllMain( 
  22.     IN HINSTANCE hinstDll, 
  23.     IN DWORD dwReason,
  24.     IN LPVOID lpvContext 
  25. )
  26. /*++
  27. Function :  DllMain
  28.  
  29. Description:
  30.  
  31.     The initialization function for this DLL.
  32.  
  33. Arguments:
  34.  
  35.     hinstDll - Instance handle of the DLL
  36.     dwReason - Reason why NT called this DLL
  37.     lpvContext - Reserved parameter for future use
  38.  
  39. Return Value:
  40.  
  41.     Returns TRUE if successfull; otherwise FALSE.
  42.  
  43. --*/
  44. {
  45.     // Note that appropriate initialization and termination code
  46.     // would be written within the switch statement below.  Because
  47.     // this example is very simple, none is currently needed.
  48.  
  49.     switch( dwReason ) {
  50.     case DLL_PROCESS_ATTACH:
  51.         break;
  52.  
  53.     case DLL_PROCESS_DETACH:
  54.         break;
  55.     }
  56.  
  57.     return(TRUE);
  58. }
  59.  
  60.  
  61. BOOL WINAPI 
  62. GetExtensionVersion( 
  63.     OUT HSE_VERSION_INFO * pVer 
  64. )
  65. /*++
  66.  
  67. Purpose:
  68.  
  69.     The first function called after IIS successfully 
  70.     loads the DLL.  The function should use the 
  71.     version structure provided by IIS to set the ISAPI
  72.     architectural version number of this extension.
  73.  
  74.     A simple text-string is also set so that 
  75.     administrators can identify the DLL.
  76.  
  77.     Note that HSE_VERSION_MINOR and HSE_VERSION_MAJOR
  78.     are constants defined in httpext.h.
  79.  
  80. Arguments: 
  81.  
  82.     pVer - points to extension version structure
  83.  
  84. Return Value:
  85.  
  86.     TRUE if successful; FALSE otherwise.    
  87.  
  88. --*/
  89. {
  90.     pVer->dwExtensionVersion = MAKELONG( HSE_VERSION_MINOR,
  91.                                              HSE_VERSION_MAJOR );
  92.  
  93.     strcpy( pVer->lpszExtensionDesc,
  94.             "IIS SDK Simple ISAPI Extension" );
  95.  
  96.     return TRUE;
  97. }
  98.  
  99.  
  100. DWORD WINAPI 
  101. HttpExtensionProc( 
  102.     IN EXTENSION_CONTROL_BLOCK * pECB
  103. )
  104. /*++
  105.  
  106. Purpose:    
  107.  
  108.     Function called by the IIS Server when a request 
  109.     for the ISAPI dll arrives.  The HttpExtensionProc                  
  110.     function processes the request and outputs the
  111.     appropriate response to the web client using
  112.     WriteClient().
  113.  
  114. Argument:
  115.  
  116.     pECB - pointer to extention control block.
  117.  
  118. Return Value:
  119.  
  120.     HSE_STATUS_SUCCESS
  121.  
  122. --*/
  123. {
  124.     static char szMessage[] = 
  125.     "<HTML>"
  126.     "<HEAD><TITLE> Simple ISAPI Extension DLL </TITLE>"
  127.     "</HEAD>\r\n"
  128.     "<BODY>"
  129.     "<P>Hello from Simple ISAPI Extension DLL!</P>\r\n"
  130.     "</BODY></HTML>\r\n\r\n";
  131.  
  132.     HSE_SEND_HEADER_EX_INFO HeaderExInfo;
  133.  
  134.     //
  135.     // prepare headers 
  136.     //
  137.  
  138.     HeaderExInfo.pszStatus = "200 OK";
  139.     HeaderExInfo.pszHeader = "Content-type: text/html\r\n\r\n";
  140.     HeaderExInfo.cchStatus = strlen( HeaderExInfo.pszStatus );
  141.     HeaderExInfo.cchHeader = strlen( HeaderExInfo.pszHeader );
  142.     HeaderExInfo.fKeepConn = FALSE;
  143.  
  144.     
  145.     //
  146.     // send headers using IIS-provided callback
  147.     // (note - if we needed to keep connection open,
  148.     //  we would set fKeepConn to TRUE *and* we would
  149.     //  need to provide correct Content-Length: header)
  150.  
  151.     pECB->ServerSupportFunction(
  152.         pECB->ConnID,
  153.         HSE_REQ_SEND_RESPONSE_HEADER_EX,
  154.         &HeaderExInfo,
  155.         NULL,
  156.         NULL
  157.         );
  158.  
  159.     //
  160.     // Calculate length of string to output to client
  161.     //
  162.  
  163.     DWORD dwBytesToWrite = strlen( szMessage );
  164.     
  165.  
  166.     //
  167.     // send text using IIS-provied callback
  168.     //
  169.  
  170.     pECB->WriteClient( pECB->ConnID, szMessage, &dwBytesToWrite, 0 );
  171.  
  172.     //
  173.     // Indicate that the call to HttpExtensionProc was successful
  174.     //
  175.  
  176.     return HSE_STATUS_SUCCESS;
  177. }
  178.  
  179.  
  180.  
  181. BOOL WINAPI
  182. TerminateExtension( 
  183.     IN DWORD dwFlags 
  184. )
  185. /*++
  186.  
  187. Routine Description:
  188.  
  189.     This function is called when the WWW service is shutdown
  190.  
  191. Arguments:
  192.  
  193.     dwFlags - HSE_TERM_ADVISORY_UNLOAD or HSE_TERM_MUST_UNLOAD
  194.  
  195. Return Value:
  196.  
  197.     TRUE if extension is ready to be unloaded,
  198.     FALSE otherwise
  199.  
  200. --*/
  201. {
  202.     // Note: We must not agree to be unloaded if we have
  203.     // any pending requests.
  204.  
  205.     return TRUE;
  206. }
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.