home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 9 / IOPROG_9.ISO / contrib / iis4 / iis4_07.cab / InvokObj.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-17  |  1.9 KB  |  83 lines

  1. // InvokObj.cpp  -> Sample ISAPI extension to invoke an automation server method
  2. // Wade A. Hilmo, August 1997
  3.  
  4. #define _WIN32_WINNT 0x0400
  5.  
  6. #include <windows.h>
  7. #include <httpext.h>
  8.  
  9.  
  10. // Import typelibrary information about the COM object
  11.  
  12. #import "GetUserName.dll"
  13.  
  14.  
  15. BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer)
  16. {
  17.     pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
  18.     lstrcpyn(pVer->lpszExtensionDesc, "InvokObj ISAPI Sample", HSE_MAX_EXT_DLL_NAME_LEN);
  19.  
  20.  
  21.     // Ensure COM is initialized
  22.  
  23.     CoInitialize(NULL);
  24.  
  25.     return TRUE;
  26. }
  27.  
  28.  
  29. DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *lpEcb)
  30. {
  31.     char szOutput[1024];
  32.     DWORD dwBuffSize;
  33.     GETUSERNAMELib::IGetUserNameObjPtr pItf;
  34.     HRESULT hr;
  35.  
  36.     // Send headers back to client
  37.  
  38.     lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, NULL, NULL, (LPDWORD)"Content-type: text/html\r\n\r\n");
  39.  
  40.  
  41.     // Initialize and instance of the automation server
  42.     
  43.     hr = pItf.CreateInstance(L"GetUserNameObj.GetUserNameObj.1");
  44.  
  45.     if (FAILED(hr))
  46.     {
  47.         wsprintf(szOutput, "<h1>Error.</h1><hr>Attempt to create instance of GetUserNameObj object failed with error %x.", hr);
  48.         dwBuffSize = strlen(szOutput);
  49.  
  50.         lpEcb->WriteClient(lpEcb->ConnID, szOutput, &dwBuffSize, 0);
  51.  
  52.         return HSE_STATUS_SUCCESS;
  53.     }
  54.  
  55.  
  56.     // Build the output using the result of the call to
  57.     // GetUserNameObj's GetMyName method
  58.     
  59.     wsprintf(szOutput, "<h1>GetUserNameObj successfully instantiated.</h1><hr>The GetMyName method returned %s.", (char *)pItf->GetMyName());
  60.     
  61.  
  62.     // Send the output back to the client
  63.     
  64.     dwBuffSize = strlen(szOutput);
  65.     lpEcb->WriteClient(lpEcb->ConnID, szOutput, &dwBuffSize, 0);
  66.  
  67.  
  68.     return HSE_STATUS_SUCCESS;
  69. }
  70.  
  71.  
  72. BOOL WINAPI TerminateExtension(DWORD dwFlags)
  73. {
  74.     // Balance the call to CoInitialize that we made in GetExtensionVersion
  75.  
  76.     CoUninitialize();
  77.  
  78.  
  79.     // It is now OK to unload
  80.     
  81.     return TRUE;
  82. }
  83.