home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 9 / IOPROG_9.ISO / contrib / iis4 / iis4_07.cab / Simple.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-05  |  4.2 KB  |  148 lines

  1. /*********************************************************************/
  2. //
  3. //  File:           Simple.cpp
  4. //
  5. //  Description:    Simple ISAPI Extension Example
  6. //
  7. //  Functions:      DllMain
  8. //                  GetExtensionVersion
  9. //                  WriteString
  10. //                  HttpExtensionProc
  11. //
  12. /*********************************************************************/
  13.  
  14.  
  15. #define _WIN32_WINNT 0x400
  16.  
  17.  
  18. #include <windows.h>
  19. #include <httpext.h>
  20.  
  21.  
  22. /*********************************************************************/
  23. //
  24. //  Function:       DllMain
  25. //
  26. //  Description:    The initialization function for this DLL.
  27. //
  28. /*********************************************************************/
  29.  
  30.  
  31. BOOL WINAPI DllMain( IN HINSTANCE   hinstDll, 
  32.                      IN DWORD       dwReason,
  33.                      IN LPVOID      lpvContext OPTIONAL )
  34. {
  35.     // Note that appropriate initialization and termination code
  36.     // would be written within the switch statement below.  Because
  37.     // this example is very simple, none is currently needed.
  38.  
  39.     switch(dwReason)
  40.     {
  41.         case DLL_PROCESS_ATTACH:
  42.         break;
  43.  
  44.         case DLL_PROCESS_DETACH:
  45.         break;
  46.     }
  47.  
  48.     return(TRUE);
  49. }
  50.  
  51.  
  52. /*********************************************************************/
  53. //
  54. //  Function:       GetExtensionVersion
  55. //
  56. //  Description:    The first function called after IIS successfully 
  57. //                  loads the DLL.  The function should use the 
  58. //                  version structure provided by IIS to set the ISAPI
  59. //                  architectural version number of this extension.
  60. //
  61. //                  A simple text-string is also set so that 
  62. //                  administrators can identify the DLL.
  63. //
  64. //                  Note that HSE_VERSION_MINOR and HSE_VERSION_MAJOR
  65. //                  are constants defined in httpext.h.
  66. //
  67. /*********************************************************************/
  68.  
  69.  
  70. BOOL WINAPI GetExtensionVersion( HSE_VERSION_INFO * pVersion )
  71. {
  72.     pVersion->dwExtensionVersion = MAKELONG( HSE_VERSION_MINOR,
  73.                                              HSE_VERSION_MAJOR );
  74.  
  75.     strcpy( pVersion->lpszExtensionDesc,
  76.             "IIS SDK Simple ISAPI Extension" );
  77.  
  78.     return(TRUE);
  79. }
  80.  
  81.  
  82. /*********************************************************************/
  83. //
  84. //  Function:       WriteString
  85. //
  86. //  Description:    Helper function that writes an ASCII String back
  87. //                  to the web client.  This function is *not* exported
  88. //                  by the DLL, and is only called by HttpExtensionProc
  89. //
  90. /*********************************************************************/
  91.  
  92.  
  93. void WriteString( EXTENSION_CONTROL_BLOCK * pECB, 
  94.                   LPCTSTR lpString )
  95. {
  96.     // Calculate length of string to output to client
  97.  
  98.     DWORD       dwBytesToWrite      =       lstrlen(lpString);
  99.     
  100.  
  101.     // Use IIS server call-back function to output text to web-client
  102.  
  103.     pECB->WriteClient( pECB->ConnID, 
  104.                        (PVOID) lpString,
  105.                        &dwBytesToWrite,
  106.                        0 );
  107. }
  108.  
  109.  
  110. /*********************************************************************/
  111. //
  112. //  Function:       HttpExtensionProc
  113. //
  114. //  Description:    Function called by the IIS Server when a request 
  115. //                  for the ISAPI dll arrives.  The HttpExtensionProc
  116. //                  function processes the request and outputs the
  117. //                  appropriate response to the web client using
  118. //                  the WriteString helper function provided above.
  119. //
  120. /*********************************************************************/
  121.  
  122.  
  123. DWORD WINAPI HttpExtensionProc( EXTENSION_CONTROL_BLOCK * pecb )
  124. {
  125.     
  126.     // Set HTML Title
  127.  
  128.     WriteString( pecb, 
  129.                  TEXT("<HEAD><TITLE> IIS SDK Simple ISAPI Extension </TITLE></HEAD>\r\n\r\n"));
  130.  
  131.  
  132.     // Output Simple Message to Web Page
  133.  
  134.     WriteString( pecb, 
  135.                  TEXT("<BODY>This is a simple ISAPI Extension from the IIS SDK!</BODY>"));
  136.  
  137.  
  138.     // Define HTML tag close
  139.  
  140.     WriteString( pecb, 
  141.                  TEXT("\r\n\r\n</TITLE>\r\n"));
  142.  
  143.  
  144.     // Indicate that the call to HttpExtensionProc was successful
  145.  
  146.     return( HSE_STATUS_SUCCESS );
  147. }
  148.