⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errcoll.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//+----------------------------------------------------------------------------
//
//
// File:
//      errcoll.cpp
//
// Contents:
//
//      Errorcollection  class implementation
//
//-----------------------------------------------------------------------------

#include "Headers.h"
#include "mssoap.h"


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorDescription::Init(TCHAR *pchDescription, TCHAR *pchActor, HRESULT hrErrorCode)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorDescription::Init(TCHAR *pchDescription, TCHAR *pchComponent, TCHAR *pchActor, TCHAR *pchFaultString, HRESULT hrErrorCode)
{
    HRESULT hr = E_FAIL;

    if (!pchDescription)
    {
        goto Cleanup;
    }
    m_pchDescription = new TCHAR[wcslen(pchDescription)+1];
    if (!m_pchDescription)
    {
        hr = E_OUTOFMEMORY;
        goto Cleanup;
    }
    wcscpy(m_pchDescription, pchDescription);
    if (pchActor)
    {
        m_pchActor = new TCHAR[wcslen(pchActor)+1];
        if (!m_pchActor)
        {
            hr = E_OUTOFMEMORY;
            goto Cleanup;
        }
        wcscpy(m_pchActor, pchActor);
    }
    if (pchComponent)
    {
        m_pchComponent = new TCHAR[wcslen(pchComponent)+1];
        if (!m_pchComponent)
        {
            hr = E_OUTOFMEMORY;
            goto Cleanup;
        }
        wcscpy(m_pchComponent, pchComponent);
        
    }
    
    if (pchFaultString)
    {
        m_bFaultEntry = true;;
        m_pchFaultString = new TCHAR[wcslen(pchFaultString)+1];
        if (!m_pchFaultString)
        {
            hr = E_OUTOFMEMORY;
            goto Cleanup;
        }
        wcscpy(m_pchFaultString, pchFaultString);
    }
    
    m_hrErrorCode = hrErrorCode;
    hr = S_OK;


Cleanup:
    ASSERT(hr==S_OK);
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////




BOOL CErrorDescription::IsFaultInfo(void)
{
    return(m_bFaultEntry);
}



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: TCHAR * CErrorDescription::GetDescription(void)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
TCHAR * CErrorDescription::GetDescription(void)
{
    return(m_pchDescription ? m_pchDescription : L"No Description");
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: TCHAR * CErrorDescription::GetActor(void)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
TCHAR * CErrorDescription::GetActor(void)
{
    return(m_pchActor);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: TCHAR * CErrorDescription::GetComponent(void)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
TCHAR * CErrorDescription::GetComponent(void)
{
    return(m_pchComponent ? m_pchComponent : L"UnknownComponent");
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorDescription::GetErrorCode(void)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorDescription::GetErrorCode(void)
{
    return(m_hrErrorCode);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorDescription::GetFaultString(void)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
TCHAR * CErrorDescription::GetFaultString(void)
{
    return(m_pchFaultString);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorListEntry::getFaultCode(BSTR *pbstrFaultCode)
//
//  parameters:
//
//  description:
//          here we look at the FIRST entry in our stack and take the correct guy out of it
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::getFaultCode(BSTR *pbstrFaultCode)
{
    HRESULT hr = S_FALSE;
    CErrorDescription *pError;

    if (m_fGotSoapError)
    {
        CHK(m_bstrFaultCode.CopyTo(pbstrFaultCode));
    }
    else
    {
        pError = GetAt(0);
        if (pError && pError->IsFaultInfo())
        {
            *pbstrFaultCode = ::SysAllocString(pError->GetComponent());
            if (!*pbstrFaultCode)
            {
                hr = E_OUTOFMEMORY;
                goto Cleanup;
            }
            hr = S_OK;
        }
    }    
    
Cleanup:
    ASSERT(SUCCEEDED(hr));
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorListEntry::getFaultActor(BSTR *pbstrActor)
//
//  parameters:
//
//  description:
//      return the actor for the running thread
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::getFaultActor(BSTR *pbstrActor)
{
    if (m_fGotSoapError && !m_bstrFaultActor.isEmpty())
    {
        return(m_bstrFaultActor.CopyTo(pbstrActor));
    }
    return m_bstrActor.CopyTo(pbstrActor);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorListEntry::setFaultActor(BSTR bstrActor)
//
//  parameters:
//
//  description:
//
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::setFaultActor(BSTR bstrActor)
{
    return (m_bstrActor.Assign(bstrActor));
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorListEntry::getFaultNamespace(BSTR *pbstrNamespace)
//
//  parameters:
//
//  description:
//      returns faultnamespace if set by ISoapError
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::getFaultNamespace(BSTR *pbstrNamespace)
{
    HRESULT hr = S_OK;

    *pbstrNamespace = 0; 
    if (m_fGotSoapError)
    {
        CHK(m_bstrFaultNamespace.CopyTo(pbstrNamespace));
    }
Cleanup:
    return hr; 
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT void CErrorListEntry::Reset(void)
//
//  parameters:
//
//  description:
//      resets current state
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void CErrorListEntry::Reset(void)
{
    m_bstrActor.Clear();
    m_bstrDescription.Clear();
    m_bstrHelpFile.Clear();
    m_bstrSource.Clear();

	m_bstrFaultString.Clear();
    m_bstrFaultActor.Clear();
    m_bstrFaultDetail.Clear();
    m_bstrFaultCode.Clear();
    m_bstrFaultNamespace.Clear(); 
    
    m_dwHelpContext = 0;
    m_hrFromException = S_OK;
    m_fGotErrorInfo = false;
    m_fGotSoapError = false; 
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorListEntry::getFaultDetailBSTR(BSTR *pbstrDetail)
//
//  parameters:
//
//  description:
//      here we walk over the current stack, starting at the top and add all those strings together...
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::getFaultDetailBSTR(BSTR *pbstrDetail)
{
    HRESULT             hr = S_OK;
    UINT                uiSize;
    UINT                uiDetailSize=0;
    CErrorDescription   *pError;   
    bool                fstart=true; 
    TCHAR               achBuffer[ONEK+1];

    
    if (m_fGotSoapError)
    {
        return(m_bstrFaultDetail.CopyTo(pbstrDetail));
    }

    // otherwise do the complicated stuff
                                                       
    uiSize = m_parrErrors->Size();
    
    // first figure out the size of this
    for (UINT i=0;i<uiSize ;i++ )
    {
        pError = GetAt(i);
        uiDetailSize += wcslen(pError->GetDescription());
        uiDetailSize += wcslen(pError->GetComponent());
        // put some spaces + errorcode around them
        uiDetailSize += 25; 
    }
    if (uiDetailSize)
    {
        uiDetailSize++;
        hr = S_OK;
        
        *pbstrDetail = ::SysAllocStringLen(0, uiDetailSize);
        if (!*pbstrDetail)
        {
            hr = E_OUTOFMEMORY;        
            goto Cleanup;
        }
        // now cut/copy them all togheter
        for (int i=(int)uiSize-1;i>=0 ;i-- )
        {
            pError = GetAt(i);
            if (wcslen(pError->GetDescription())>0)
            {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -