// Power.cpp : Implementation of CCATLPwrApp and DLL registration. #include "stdafx.h" #include "CATLPwr.h" #include "Power.h" #include "context.h" ///////////////////////////////////////////////////////////////////////////// // STDMETHODIMP CPower::InterfaceSupportsErrorInfo(REFIID riid) { static const IID* arr[] = { &IID_IPower, }; for (int i=0;i piServerVariables; HRESULT hr = cxt.Request()->get_ServerVariables(&piServerVariables); if (FAILED(hr)) return hr; // Get the SCRIPT_NAME item from the ServerVariables collection CComVariant vtIn(OLESTR("SCRIPT_NAME")), vtOut; hr = piServerVariables->get_Item(vtIn, &vtOut); if (FAILED(hr)) return hr; // Get the SCRIPT_NAME item from the ServerVariables collection // vtOut Contains an IDispatch Pointer. To fetch the value // for SCRIPT_NAME, you must get the Default Value for the // Object stored in vtOut using VariantChangeType. hr = VariantChangeType(&vtOut, &vtOut, 0, VT_BSTR); // Copy and return SCRIPT_NAME if (SUCCEEDED(hr)) *pbstrOutValue = ::SysAllocString(V_BSTR(&vtOut)); return hr; } // ASP-specific Power Method STDMETHODIMP CPower::myPowerMethod() { CContext cxt; if ( FAILED( cxt.Init( CContext::get_Request | CContext::get_Response ) ) ) { return E_FAIL; } // Get the ServerVariables Collection CComPtr piServerVariables; HRESULT hr = cxt.Request()->get_ServerVariables(&piServerVariables); if (FAILED(hr)) return hr; // Get the HTTP_USER_AGENT item from the ServerVariables collection CComVariant vtIn(OLESTR("HTTP_USER_AGENT")), vtOut; hr = piServerVariables->get_Item(vtIn, &vtOut); if (FAILED(hr)) return hr; // vtOut Contains an IDispatch Pointer. To fetch the value // for HTTP_USER_AGENT, you must get the Default Value for the // Object stored in vtOut using VariantChangeType. hr = VariantChangeType(&vtOut, &vtOut, 0, VT_BSTR); if (SUCCEEDED(hr)) { // Look for "MSIE" in HTTP_USER_AGENT string if (wcsstr(vtOut.bstrVal, L"MSIE") != NULL) cxt.Response()->Write(CComVariant( OLESTR("You are using a very powerful browser."))); else cxt.Response()->Write(CComVariant( OLESTR("Try Internet Explorer today!"))); } return hr; }