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

  1. /*++
  2.  
  3. Copyright (c) 1997  Microsoft Corporation
  4.  
  5. Module Name:    InvokObj.cpp
  6.  
  7. Abstract:
  8.  
  9.     ISAPI Extension sample to invoke an automation server method
  10.  
  11. --*/
  12.  
  13. #define _WIN32_WINNT 0x0400
  14. #include <windows.h>
  15. #include <httpext.h>
  16.  
  17.  
  18. //
  19. // Import type library information about the COM object
  20. //
  21.  
  22. #import "GetUserName.dll"
  23.  
  24.  
  25. BOOL WINAPI 
  26. GetExtensionVersion(
  27.     HSE_VERSION_INFO *pVer
  28.     )
  29. /*++
  30.  
  31. Purpose:
  32.  
  33.     This is required ISAPI Extension DLL entry point.
  34.  
  35. Arguments:
  36.  
  37.     pVer - poins to extension version info structure 
  38.  
  39. Returns:
  40.  
  41.     always returns TRUE
  42.  
  43. --*/
  44. {
  45.     pVer->dwExtensionVersion = MAKELONG( HSE_VERSION_MINOR, 
  46.                                          HSE_VERSION_MAJOR );
  47.     lstrcpyn( pVer->lpszExtensionDesc, 
  48.         "InvokObj ISAPI Sample", HSE_MAX_EXT_DLL_NAME_LEN );
  49.  
  50.     //
  51.     // Ensure COM is initialized
  52.     //
  53.  
  54.     CoInitialize( NULL );
  55.  
  56.     return TRUE;
  57. }
  58.  
  59.  
  60. DWORD WINAPI 
  61. HttpExtensionProc(
  62.     EXTENSION_CONTROL_BLOCK *pECB
  63.     )
  64. /*++
  65.  
  66. Purpose:
  67.  
  68.     Demonstrate how to create an instance of the automation object
  69.     using VC++ 5.0 extensions and how to invoke its method.
  70.  
  71. Arguments:
  72.  
  73.     pECB - pointer to the extenstion control block 
  74.  
  75. Returns:
  76.  
  77.     HSE_STATUS_SUCCESS on successful transmission completion
  78.     HSE_STATUS_ERROR on failure
  79.  
  80. --*/
  81. {
  82.     char szOutput[1024];
  83.     DWORD dwBuffSize;
  84.     GETUSERNAMELib::IGetUserNameObjPtr pItf;
  85.     HSE_SEND_HEADER_EX_INFO HeaderExInfo;
  86.     HRESULT hr;
  87.  
  88.     //
  89.     // Send headers back to client
  90.     //
  91.  
  92.     HeaderExInfo.pszStatus = "200 OK";
  93.     HeaderExInfo.cchStatus = strlen( HeaderExInfo.pszStatus );
  94.     HeaderExInfo.pszHeader = "Content-type: text/html\r\n\r\n";
  95.     HeaderExInfo.cchHeader = strlen( HeaderExInfo.pszHeader );
  96.     HeaderExInfo.fKeepConn = FALSE;
  97.  
  98.     pECB->ServerSupportFunction( pECB->ConnID, 
  99.         HSE_REQ_SEND_RESPONSE_HEADER_EX,
  100.         &HeaderExInfo, NULL, NULL );
  101.  
  102.     //
  103.     // Initialize an instance of the automation server
  104.     //
  105.     
  106.     hr = pItf.CreateInstance( L"GetUserNameObj.GetUserNameObj.1" );
  107.  
  108.     if ( FAILED( hr ) )
  109.     {
  110.         wsprintf( szOutput, "<h1>Error.</h1><hr>Attempt to create instance "
  111.             "of GetUserNameObj object failed with error %x.", hr );
  112.         dwBuffSize = strlen( szOutput );
  113.  
  114.         pECB->WriteClient( pECB->ConnID, szOutput, &dwBuffSize, 0 );
  115.  
  116.         return HSE_STATUS_SUCCESS;
  117.     }
  118.  
  119.  
  120.     //
  121.     // Build the output using the result of the call to
  122.     // GetUserNameObj's GetMyName method
  123.     //
  124.     
  125.     wsprintf( szOutput, "<h1>GetUserNameObj successfully instantiated."
  126.         "</h1><hr>The GetMyName method returned %s.", 
  127.         (char *)pItf->GetMyName( ) );
  128.     
  129.  
  130.     //
  131.     // Send the output back to the client
  132.     //
  133.     
  134.     dwBuffSize = strlen( szOutput );
  135.     pECB->WriteClient( pECB->ConnID, szOutput, &dwBuffSize, 0 );
  136.  
  137.  
  138.     return HSE_STATUS_SUCCESS;
  139. }
  140.  
  141.  
  142. BOOL WINAPI 
  143. TerminateExtension(
  144.     DWORD dwFlags
  145.     )
  146. /*++
  147.  
  148. Purpose:
  149.  
  150.     This is optional ISAPI extension DLL entry point.
  151.     If present, it will be called before unloading the DLL,
  152.     giving it a chance to perform any shutdown procedures.
  153.     
  154. Arguments:
  155.     
  156.     dwFlags - specifies whether the DLL can refuse to unload or not
  157.     
  158. Returns:
  159.     
  160.     TRUE, if the DLL can be unloaded
  161.     
  162. --*/
  163. {
  164.     //
  165.     // Balance the call to CoInitialize that we made in GetExtensionVersion
  166.     //
  167.  
  168.     CoUninitialize( );
  169.  
  170.     //
  171.     // It is now OK to unload
  172.     //
  173.     
  174.     return TRUE;
  175. }
  176.  
  177.  
  178.  
  179.