errcoll.cpp

来自「Windows CE 6.0 Server 源码」· C++ 代码 · 共 1,170 行 · 第 1/3 页

CPP
1,170
字号
                if (fstart)
                {
                    wcscpy(*pbstrDetail, pError->GetComponent());
                    wcscat(*pbstrDetail, L":");                    
                    wcscat(*pbstrDetail, pError->GetDescription());
                    fstart=false;
                }
                else
                {
                    wcscat(*pbstrDetail, L" - ");
                    wcscat(*pbstrDetail, pError->GetComponent());
                    wcscat(*pbstrDetail, L":");                    
                    wcscat(*pbstrDetail, pError->GetDescription());
                }
                // now insert the HR
                swprintf(achBuffer, L" HRESULT=0x%lX", pError->GetErrorCode());
                wcscat(*pbstrDetail, achBuffer);
                
            }
        }
    }


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



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorListEntry::getFaultString(BSTR *pbstrFaultString)
//
//  parameters:
//
//  description:
//      picks the latest entry in the error collection as the faultstring...
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::getFaultString(BSTR *pbstrFaultString)
{
    CErrorDescription   *pError;   
    HRESULT             hr = E_FAIL;
    UINT                uiSize;
    bool                fFaultString=true;

    
    if (m_fGotSoapError)
    {
        return(m_bstrFaultString.CopyTo(pbstrFaultString));
    }
    if (m_fGotErrorInfo)
    {
        return (m_bstrDescription.CopyTo(pbstrFaultString));
    }


    // get the first guy                                                   
    pError = GetAt(0);
    if (pError)
    {
    
        if (pError->GetFaultString()==0)
        {
            uiSize = wcslen(pError->GetDescription());
            uiSize += wcslen(pError->GetComponent());
            // put some spaces around them
            uiSize += 3;
            fFaultString = false;
                
        }
        else
        {
            uiSize = wcslen(pError->GetFaultString());            
        }
    
        
        *pbstrFaultString = ::SysAllocStringLen(0, uiSize);
        if (!*pbstrFaultString)
        {
            hr = E_OUTOFMEMORY;
            goto Cleanup;
        }
        
        if (fFaultString)
        {
            wcscpy(*pbstrFaultString, pError->GetFaultString());
        }
        else
        {
            wcscpy(*pbstrFaultString, pError->GetComponent());
            wcscat(*pbstrFaultString, L": ");
            wcscat(*pbstrFaultString, pError->GetDescription());
        }
        hr = S_OK;
    }
Cleanup:
    return(hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function:         HRESULT CErrorListEntry::SetErrorInfo(, 
//
//  parameters:
//
//  description:
//      set's the ERRORINFO information
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::SetErrorInfo(BSTR bstrDescription, 
                BSTR bstrSource, BSTR bstrHelpFile, 
                DWORD dwHelpContext, HRESULT hrFromException)
{
    HRESULT hr;

    CHK(m_bstrDescription.Assign(bstrDescription));
    CHK(m_bstrSource.Assign(bstrSource));
    CHK(m_bstrHelpFile.Assign(bstrHelpFile));
    m_dwHelpContext = dwHelpContext;
    m_hrFromException = hrFromException;

    m_fGotErrorInfo = true; 

Cleanup:
    return (hr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function:         HRESULT CErrorListEntry::GetErrorInfo(, 
//
//  parameters:
//
//  description:
//      surprise: get's the ERRORINFO information
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::GetErrorInfo(BSTR *pbstrDescription, 
                        BSTR *pbstrSource, BSTR *pbstrHelpFile, 
                        DWORD *pdwHelpContext, HRESULT *phrFromException)
{
    HRESULT hr=S_FALSE;

    if (m_fGotErrorInfo)
    {
        CHK(m_bstrDescription.CopyTo(pbstrDescription));
        CHK(m_bstrSource.CopyTo(pbstrSource));
        CHK(m_bstrHelpFile.CopyTo(pbstrHelpFile));    

        *pdwHelpContext = m_dwHelpContext;
        *phrFromException = m_hrFromException;
    }    

Cleanup:
    return (hr);
    
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function:         HRESULT CErrorListEntry::SetSoapError
//
//  parameters:
//
//  description:
//      sets the soaperror for this list
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::SetSoapError(BSTR bstrFaultString, BSTR bstrFaultActor, BSTR bstrDetail, BSTR bstrFaultCode, BSTR bstrNameSpace)
{
    HRESULT hr; 

    CHK(m_bstrFaultString.Assign(bstrFaultString, true));
    CHK(m_bstrFaultActor.Assign(bstrFaultActor, true));
    CHK(m_bstrFaultDetail.Assign(bstrDetail, true));
    CHK(m_bstrFaultCode.Assign(bstrFaultCode, true));
    CHK(m_bstrFaultNamespace.Assign(bstrNameSpace, true));

    m_fGotSoapError = true; 
Cleanup:
    return hr; 
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function:         HRESULT CErrorListEntry::GetSoapError
//
//  parameters:
//
//  description:
//      gets the soaperror for this list, S_FALSE if none there...
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::GetSoapError(BSTR *pbstrFaultString, BSTR *pbstrFaultActor, BSTR *pbstrDetail, BSTR *pbstrFaultCode, BSTR *pbstrNameSpace)
{
    HRESULT hr = S_FALSE;

    if (m_fGotSoapError)
    {
        CHK(m_bstrFaultString.CopyTo(pbstrFaultString));
        CHK(m_bstrFaultActor.CopyTo(pbstrFaultActor));
        CHK(m_bstrFaultDetail.CopyTo(pbstrDetail));
        CHK(m_bstrFaultCode.CopyTo(pbstrFaultCode));
        CHK(m_bstrFaultNamespace.CopyTo(pbstrNameSpace));
    }

Cleanup:
    return hr; 
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function:         HRESULT CErrorListEntry::GetReturnCode(HRESULT *phrReturnCode)
//
//  parameters:
//
//  description:
//      returns the returncode : either from errorinfo, ot the first entry in the stack
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorListEntry::GetReturnCode(HRESULT *phrReturnCode)
{
    if (m_fGotErrorInfo)
    {
        *phrReturnCode = m_hrFromException;
        return S_OK; 
    }
    else
    {
        CErrorDescription *pError = GetAt(0);
        if (pError)
        {
            *phrReturnCode = pError->GetErrorCode();
            return S_OK;
        }

    }
    return E_FAIL;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function:         void    CErrorCollection::setActor(BSTR *pbstrActor)
//
//  parameters:
//
//  description:
//      sets the actor attribute for the errorlist...
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorCollection::setActor(BSTR bstrActor)
{
    HRESULT             hr = E_FAIL;
    CErrorListEntry     *pList = 0; 

    pList = getCurrentList();
    CHK_BOOL(pList, E_OUTOFMEMORY);
    CHK(pList->setFaultActor(bstrActor));

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorCollection::AddErrorEntry(TCHAR *pchDescription, TCHAR *pchActor, HRESULT hrErrorCode)
//
//  parameters:
//      2 strings and the HR
//  description:
//      adds this to the bucket list for a threadid
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorCollection::AddErrorEntry(TCHAR *pchDescription, TCHAR *pchComponent, 
                                        TCHAR *pchActor, TCHAR *pchFaultString, HRESULT hrErrorCode)
{
    HRESULT             hr = E_FAIL;
    CErrorDescription   *pEntry=0;
    CErrorListEntry     *pList = 0; 

    
    pEntry = new CErrorDescription();
    CHK_BOOL(pEntry, E_OUTOFMEMORY);
    
    CHK(pEntry->Init(pchDescription, pchComponent, pchActor, pchFaultString, hrErrorCode));

    pList = getCurrentList();
    CHK_BOOL(pList, E_OUTOFMEMORY);

    CHK(pList->AddEntry(pEntry))

    // ownership for pEntry successfully passed to the errorcollection    
    pEntry = 0;
    


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

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorCollection::AddErrorFromSoapError(ISOAPError * pSoapError)
//
//  parameters:
//
//  description:
//      is used to add the ISoapErrorInfo after a call to a server object failed
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorCollection::AddErrorFromSoapError(IDispatch * pDispatch)
{
    CAutoRefc<ISOAPError>   pISoapError=0;
    HRESULT                 hr; 
    CAutoBSTR               bstrFaultString;
    CAutoBSTR               bstrFaultActor;
    CAutoBSTR               bstrDetail;
    CAutoBSTR               bstrFaultCode;
    CAutoBSTR               bstrNamespace; 
    
	hr = pDispatch->QueryInterface(IID_ISOAPError, (void **)&pISoapError); 
    if (SUCCEEDED(hr) && pISoapError)    
    {
        CErrorListEntry     *pList = 0; 
        pList = getCurrentList();
        CHK_BOOL(pList, E_OUTOFMEMORY);
        
        CHK(pISoapError->get_faultstring(&bstrFaultString));
        CHK(pISoapError->get_faultactor(&bstrFaultActor));
        CHK(pISoapError->get_detail(&bstrDetail));
        CHK(pISoapError->get_faultcode(&bstrFaultCode));
        CHK(pISoapError->get_faultcodeNS(&bstrNamespace));
        
        if (!bstrDetail.isEmpty() && !bstrFaultString.isEmpty())
        {
            CHK(pList->SetSoapError(bstrFaultString, 
                             bstrFaultActor, 
                             bstrDetail, 
                             bstrFaultCode, 
                             bstrNamespace));
        }
    }

Cleanup:
    return hr;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////
//  function: HRESULT CErrorCollection::AddErrorFromErrorInfo(LPEXCEPINFO pExecpInfo, HRESULT hrErrorCode)
//
//  parameters:
//
//  description:
//      is used to add the exepinfo/errorinfo after a call to a server object failed
//  returns: 
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CErrorCollection::AddErrorFromErrorInfo(LPEXCEPINFO pexepInfo, HRESULT hrErrorCode)
{
    HRESULT                 hr=S_OK;
    CAutoRefc<IErrorInfo>      pIErrInfo;

⌨️ 快捷键说明

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