示例#1
0
static void ErrorDump()
{
#if 0
    USES_CONVERSION;
    CDBErrorInfo einfo;
    BSTR bstrDescription;
    ULONG nRecords = 0;
    HRESULT hr = einfo.GetErrorRecords(&nRecords);
    if(SUCCEEDED(hr) && nRecords > 0)
    {
        LCID lcid = GetSystemDefaultLCID();
        for(ULONG nIndex = 0; nIndex < nRecords; nIndex++)
        {
            hr = einfo.GetAllErrorInfo(nIndex, lcid, &bstrDescription);
            if(SUCCEEDED(hr))
            {
                AfxMessageBox(OLE2T(bstrDescription));
                SysFreeString(bstrDescription);
            }
        }
    }
#endif
    USES_CONVERSION;
    CComPtr<IErrorInfo> pErrInfo;
    HRESULT hr = ::GetErrorInfo(0, &pErrInfo);
    if(SUCCEEDED(hr))
    {
        _bstr_t bstrErrDescription;
        pErrInfo->GetDescription((BSTR *) &bstrErrDescription);

        CString strDescription = W2T(bstrErrDescription);
        OutputDebugString(strDescription);

    }
}
示例#2
0
BOOL CErrorsDialog::OnInitDialog()
{

	CDialog::OnInitDialog();

	// Set the help button to be inactive
	m_ctlHelp.EnableWindow(FALSE);

	// Read in the error information from IErrorRecords
	CDBErrorInfo errInfo;
	ULONG ulRecords = 0;
	HRESULT hr;

	hr = errInfo.GetErrorRecords(m_spUnk, m_iid, &ulRecords);
	if (FAILED(hr) || hr == S_FALSE || ulRecords == 0)
	{
		CString strError;
		if( strError.LoadString(IDS_NOSPECIFIED_SOURCE) == FALSE)
		{
			AfxThrowResourceException();
		}
		m_ctlListSource.AddString(strError);
	}
	else
	{
		LCID lcid = GetUserDefaultLCID();
		for (ULONG l=0; l<ulRecords; l++)
		{
			// Get the error information from the source
			struct MYERRORINFO* pInfo = new MYERRORINFO;
			#pragma warning(disable: 6011) // unexpected null dereference prefast warning
			hr = errInfo.GetAllErrorInfo(l, lcid, &pInfo->bstrDescription,
				&pInfo->bstrSource, &pInfo->guid, &pInfo->dwHelpContext,
				&pInfo->bstrHelpFile);
			#pragma warning(default: 6011) // unexpected null dereference prefast warning
			if (FAILED(hr))
			{
				delete pInfo;
				continue;
			}

			m_listErrorInfo.AddTail(pInfo);

			// Add the information to the list view
			if (pInfo->bstrSource)
				m_ctlListSource.AddString(COLE2T(pInfo->bstrSource));
			else
				m_ctlListSource.AddString(_T("Unspecified error."));
		}
	}
	m_ctlListSource.SetCurSel(0);
	SelectSource(0);
	return TRUE;  // return TRUE unless you set the focus to a control
				  // EXCEPTION: OCX Property Pages should return FALSE
}
void DisplayOLEDBErrorRecords(HRESULT hrErr = S_OK)
{
	CDBErrorInfo ErrorInfo;
	ULONG        cRecords;
	HRESULT      hr;
	ULONG        i;
	CComBSTR     bstrDesc, bstrHelpFile, bstrSource;
	GUID         guid;
	DWORD        dwHelpContext;
	WCHAR        wszGuid[40];
	USES_CONVERSION;

  TCERRLOG_BEGIN_SIZE(_MAX_PATH * 8);

	// If the user passed in an HRESULT then trace it
	if (hrErr != S_OK)
  {
		TCERRLOG_PART1("OLE DB Error Record dump for hr = 0x%x\n", hrErr);
  }

	LCID lcLocale = GetSystemDefaultLCID();

	hr = ErrorInfo.GetErrorRecords(&cRecords);
	if (FAILED(hr) && ErrorInfo.m_spErrorInfo == NULL)
	{
		TCERRLOG_PART1("No OLE DB Error Information found: hr = 0x%x\n", hr);
	}
	else
	{
		for (i = 0; i < cRecords; i++)
		{
			hr = ErrorInfo.GetAllErrorInfo(i, lcLocale, &bstrDesc, &bstrSource, &guid,
										&dwHelpContext, &bstrHelpFile);
			if (FAILED(hr))
			{
				TCERRLOG_PART1("OLE DB Error Record dump retrieval failed: hr = 0x%x\n", hr );
				return;
			}
			StringFromGUID2(guid, wszGuid, sizeof(wszGuid) / sizeof(WCHAR));
			TCERRLOG_PART5(
				"Source:\"%ls\"\nDescription:\"%ls\"\nHelp File:\"%ls\"\nHelp Context:%4d\nGUID:%ls\n",
				bstrSource, bstrDesc, bstrHelpFile, dwHelpContext, wszGuid);
			bstrSource.Empty();
			bstrDesc.Empty();
			bstrHelpFile.Empty();
		}
	}
  TCERRLOG_END
}