home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / context.cpp < prev    next >
C/C++ Source or Header  |  1997-10-25  |  2KB  |  109 lines

  1. /*++
  2.  
  3.     Copyright    (c)    1997    Microsoft Corporation
  4.  
  5.     Module    Name :
  6.  
  7.         context.h
  8.  
  9.     Abstract:
  10.         A class to retrieve and release ASP intrinsics
  11.  
  12.     Author:
  13.  
  14.         Neil Allain   ( a-neilal )       August-1997 
  15.  
  16.     Revision History:
  17.  
  18. --*/
  19. #include "stdafx.h"
  20. #include <asptlb.h>
  21. #include "context.h"
  22.  
  23.  
  24. //---------------------------------------------------------------------------
  25. //    GetServerObject
  26. //
  27. //    Get an instrinic object from the current Object context
  28. //---------------------------------------------------------------------------
  29. HRESULT
  30. CContext::GetServerObject(
  31.     IGetContextProperties*    pProps,
  32.     BSTR                    bstrObjName,
  33.     const IID&                iid,
  34.     void**                    ppObj
  35. )
  36. {
  37.     HRESULT rc = E_FAIL;
  38.     _ASSERT( pProps );
  39.     _ASSERT( bstrObjName );
  40.     _ASSERT( ppObj );
  41.     if ( pProps && bstrObjName && ppObj )
  42.     {
  43.         *ppObj = NULL;
  44.         CComVariant vt;
  45.         if ( !FAILED( pProps->GetProperty( bstrObjName, &vt ) ) )
  46.         {
  47.             if ( V_VT(&vt) == VT_DISPATCH )
  48.             {
  49.                 IDispatch* pDispatch = V_DISPATCH(&vt);
  50.                 if ( pDispatch )
  51.                 {
  52.                     rc = pDispatch->QueryInterface( iid, ppObj );
  53.                 }
  54.             }
  55.         }
  56.     }
  57.     return rc;
  58. }
  59.  
  60.  
  61. HRESULT
  62. CContext::Init(
  63.     DWORD    dwFlags // which instrinsics to initialize
  64. )
  65. {
  66.     HRESULT rc = E_FAIL;
  67.     CComPtr<IObjectContext> pObjContext;
  68.  
  69.     rc = ::GetObjectContext( &pObjContext );
  70.     if ( !FAILED( rc ) )
  71.     {
  72.         CComPtr<IGetContextProperties> pProps;
  73.         rc = pObjContext->QueryInterface( IID_IGetContextProperties, (void**)&pProps );
  74.         if ( !FAILED( rc ) )
  75.         {
  76.             CComBSTR bstrObj;
  77.             if ( dwFlags & get_Request )
  78.             {
  79.                 bstrObj = "Request";
  80.                 rc = GetServerObject( pProps, bstrObj, IID_IRequest, (void**)&m_piRequest );
  81.             }
  82.             if ( !FAILED(rc) && ( dwFlags & get_Response ) )
  83.             {
  84.                 bstrObj = "Response";
  85.                 rc = GetServerObject( pProps, bstrObj, IID_IResponse, (void**)&m_piResponse );
  86.             }
  87.  
  88.             if ( !FAILED(rc) && ( dwFlags & get_Session ) )
  89.             {
  90.                 bstrObj = "Session";
  91.                 rc = GetServerObject( pProps, bstrObj, IID_ISessionObject, (void**)&m_piSession );
  92.             }
  93.  
  94.             if ( !FAILED(rc) && ( dwFlags & get_Server ) )
  95.             {
  96.                 bstrObj = "Server";
  97.                 rc = GetServerObject( pProps, bstrObj, IID_IServer, (void**)&m_piServer );
  98.             }
  99.  
  100.             if ( !FAILED(rc) && ( dwFlags & get_Application ) )
  101.             {
  102.                 bstrObj = "Application";
  103.                 rc = GetServerObject( pProps, bstrObj, IID_IApplicationObject, (void**)&m_piApplication );
  104.             }
  105.         }
  106.     }
  107.     return rc;
  108. }
  109.