home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2000 May / MICD_2000_05.iso / CBuilder5 / INSTALL / DATA1.CAB / Program_Built_Files / Include / Vcl / asphlpr.cpp < prev    next >
C/C++ Source or Header  |  2000-02-01  |  6KB  |  189 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3.  
  4. #define INITGUID
  5. #include <objbase.h>
  6. #include <initguid.h>
  7. #include <utilcls.h>
  8. #include <atlbase.h>
  9. #include <asptlb.h>                                             
  10. #include <mtx.h>
  11.  
  12. #include <mtshlpr.h>
  13. #include <asphlpr.h>
  14. //---------------------------------------------------------------------------
  15.  
  16. STDMETHODIMP TASPObject::OnStartPage(LPUNKNOWN AScriptingContext)
  17. {
  18.   HRESULT hResult;
  19.  
  20.   if (!AScriptingContext)
  21.     return E_POINTER;
  22.  
  23.   CComQIPtr<IScriptingContext, &IID_IScriptingContext> AContext = AScriptingContext;
  24.  
  25.   if (!AContext)
  26.     return E_NOINTERFACE;
  27.  
  28.   hResult = AContext->get_Request(&m_Request);
  29.   if (SUCCEEDED(hResult))
  30.   {
  31.     hResult = AContext->get_Response(&m_Response);
  32.     if (SUCCEEDED(hResult))
  33.     {
  34.       hResult = AContext->get_Server(&m_Server);
  35.       if (SUCCEEDED(hResult))
  36.       {
  37.         hResult = AContext->get_Session(&m_Session);
  38.         if (SUCCEEDED(hResult))
  39.           hResult = AContext->get_Application(&m_Application);
  40.       }
  41.     }
  42.   }
  43.  
  44.   if (FAILED(hResult))
  45.   {
  46.     if (m_Request)
  47.       m_Request.Release();
  48.     if (m_Response)
  49.       m_Response.Release();
  50.     if (m_Server)
  51.       m_Server.Release();
  52.     if (m_Session)
  53.       m_Session.Release();
  54.     if (m_Application)
  55.       m_Application.Release();
  56.   }
  57.  
  58.   return hResult;
  59. };
  60. //---------------------------------------------------------------------------
  61. STDMETHODIMP TASPObject::OnEndPage()
  62. {
  63.   HRESULT hr = E_FAIL;
  64.  
  65.   ATLTRY
  66.   (
  67.     m_Request.Release();
  68.     m_Response.Release();
  69.     m_Application.Release();
  70.     m_Session.Release();
  71.     m_Server.Release();
  72.     hr = S_OK;
  73.   )
  74.  
  75.   return hr;
  76. };
  77. //---------------------------------------------------------------------------
  78. IRequest* TMTSASPObject::GetRequest(void)
  79. {
  80.   return m_Request.p;
  81. };
  82. //---------------------------------------------------------------------------
  83. IResponse* TMTSASPObject::GetResponse(void)
  84. {
  85.   return m_Response.p;
  86. };
  87. //---------------------------------------------------------------------------
  88. IApplicationObject* TMTSASPObject::GetApplication(void)
  89. {
  90.   return m_Application.p;
  91. };
  92. //---------------------------------------------------------------------------
  93. ISessionObject* TMTSASPObject::GetSession(void)
  94. {
  95.   return m_Session.p;
  96. };
  97. //---------------------------------------------------------------------------
  98. IServer* TMTSASPObject::GetServer(void)
  99. {
  100.   return m_Server.p;
  101. };
  102. //---------------------------------------------------------------------------
  103. TMTSASPObject::TMTSASPObject()
  104. {
  105.   CComPtr<IGetContextProperties> ContextProperties;
  106.   HRESULT hr = E_FAIL;
  107.   TVariant var;
  108.   IUnknown* Temp;
  109.  
  110.   static TMtsDll Mts;
  111.   // note: this will throw if MTS services are not available.
  112.   hr = Mts.Get_ObjectContext(&m_spObjectContext);
  113.  
  114.   if (SUCCEEDED(hr))
  115.   {
  116.     hr = m_spObjectContext->QueryInterface(IID_IGetContextProperties, (void **)&ContextProperties);
  117.     if (SUCCEEDED(hr))
  118.     {
  119.       hr = ContextProperties->GetProperty(OLESTR("Request"), var); /* do not localize */
  120.       if (SUCCEEDED(hr))
  121.       {
  122.         Temp = var; /* conversion AddRefs, be sure to Release() */
  123.         hr = Temp->QueryInterface(IID_IRequest, (void **)&m_Request);
  124.         Temp->Release();
  125.         if (SUCCEEDED(hr))
  126.           hr = ContextProperties->GetProperty(OLESTR("Response"), var); /* do not localize */
  127.         if (SUCCEEDED(hr))
  128.         {
  129.           Temp = var; /* conversion AddRefs, be sure to Release() */
  130.           hr = Temp->QueryInterface(IID_IResponse, (void **)&m_Response);
  131.           Temp->Release();
  132.           if (SUCCEEDED(hr))
  133.             hr = ContextProperties->GetProperty(OLESTR("Application"), var); /* do not localize */
  134.           if (SUCCEEDED(hr))
  135.           {
  136.             Temp = var; /* conversion AddRefs, be sure to Release() */
  137.             hr = Temp->QueryInterface(IID_IApplicationObject, (void **)&m_Application);
  138.             Temp->Release();
  139.             if (SUCCEEDED(hr))
  140.               hr = ContextProperties->GetProperty(OLESTR("Session"), var); /* do not localize */
  141.             if (SUCCEEDED(hr))
  142.             {
  143.               Temp = var; /* conversion AddRefs, be sure to Release() */
  144.               hr = Temp->QueryInterface(IID_ISessionObject, (void **)&m_Session);
  145.               Temp->Release();
  146.               if (SUCCEEDED(hr))
  147.                 hr = ContextProperties->GetProperty(OLESTR("Server"), var); /* do not localize */
  148.               if (SUCCEEDED(hr))
  149.               {
  150.                 Temp = var; /* conversion AddRefs, be sure to Release() */
  151.                 hr = Temp->QueryInterface(IID_IServer, (void **)&m_Server);
  152.                 Temp->Release();
  153.               }
  154.             }
  155.           }
  156.         }
  157.       }
  158.     }
  159.   }
  160. };
  161. //---------------------------------------------------------------------------
  162. TMTSASPObject::~TMTSASPObject()
  163. {
  164.   ATLTRY
  165.   (
  166.     if (m_spObjectContext)
  167.       m_spObjectContext.Release();
  168.     if (m_Request)
  169.       m_Request.Release();
  170.     if (m_Response)
  171.       m_Response.Release();
  172.     if (m_Application)
  173.       m_Application.Release();
  174.     if (m_Session)
  175.       m_Session.Release();
  176.     if (m_Server)
  177.       m_Server.Release();
  178.   )
  179. };
  180. //---------------------------------------------------------------------------
  181. IObjectContext* TMTSASPObject::getObjectContext(void)
  182. {
  183.   return m_spObjectContext.p;
  184. };
  185. //---------------------------------------------------------------------------
  186.  
  187. #pragma package(smart_init)
  188.  
  189.