Listing 8: The Epilog() method.

HRESULT CUltraMaxService::Epilog(HRESULT hr)
{
    if ( FAILED(hr) )
    {
        // Error information
        CComPtr<IErrorInfo> Error;
        if ( SUCCEEDED(GetErrorInfo(0, &Error)) )
           Error->GetDescription(&m_ErrorDesc);
        else
            m_ErrorDesc = ::SysAllocString(L"Unknown error occurred.");
    }
    // Write object state to session
    CComBSTR str;
    str.Attach(m_pUltraMax->ToString());
    m_spSession->SetVariable("state", CComVariant(str));
    return hr;
}