stcomerror.cpp

来自「windows ce开发技巧与实例光盘代码」· C++ 代码 · 共 79 行

CPP
79
字号
#include "stdafx.h"
#include "STComError.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif



//////////////////////////////////////////////////////////////////////
// CSTComError
//////////////////////////////////////////////////////////////////////

CSTComError::CSTComError() 
	: m_hrError(S_OK)
{
}

CSTComError::CSTComError(HRESULT hrError) 
	: m_hrError(hrError)
{
}

CSTComError::CSTComError(const CSTComError &src) 
	: m_hrError(src.m_hrError)
{
}

CSTComError& CSTComError::operator=(const CSTComError &src)
{
	m_hrError = src.m_hrError;
	return *this;
}

HRESULT CSTComError::Error() const
{
	return m_hrError;
}

CSTComError lastComError;

CSTComError GetComError()
{
	return lastComError;
}


//////////////////////////////////////////////////////////////////////
// COM error handlers
//////////////////////////////////////////////////////////////////////

void __stdcall _com_issue_error(HRESULT hResult)
{
#ifndef ST_IGNORE_COM_EXCEPTIONS
	DWORD *data = new DWORD[1];
	data[0] = hResult;
	RaiseException(EXCEPTION_COMERROR, 0, 1, data);
#endif /*ST_IGNORE_COM_EXCEPTIONS*/
}

void __stdcall _com_issue_errorex(HRESULT hResult, IUnknown* pUnknown, REFIID refid)
{
#ifndef ST_IGNORE_COM_EXCEPTIONS
	DWORD *data = new DWORD[1];
	data[0] = hResult;
	RaiseException(EXCEPTION_COMERROR, 0, 1, data);
#endif /*ST_IGNORE_COM_EXCEPTIONS*/
}

int ComErrorFilterFunction(DWORD dwCode, LPEXCEPTION_POINTERS info)
{
	HRESULT hrResult = info->ExceptionRecord->ExceptionInformation[0];
	lastComError = CSTComError(hrResult);
	return (dwCode==EXCEPTION_COMERROR);
}

⌨️ 快捷键说明

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