1 #ifndef _ERROR_H__FC8EA04F_57D6_4002_81BE_F37E1FA54F47_
2 #define _ERROR_H__FC8EA04F_57D6_4002_81BE_F37E1FA54F47_
7 #define VERBOSE_ERR 0 //Make this 0 to suppress the default MsgBox()
16 inline LPCTSTR GetErrorDetails(LPTSTR lpszBuf, DWORD dwBufLen, DWORD dwErrorCode = GetLastError())
18 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
19 NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), lpszBuf, dwBufLen, NULL );
25 enum {ErrMsgBufSize = 1023};
27 TCHAR m_szErrBuf[ ErrMsgBufSize + 1 ];
30 enum ErrReportingMode { Mode_MessageBox, Mode_OutputDebugString };
33 ErrReportingMode m_ReportingMode;
37 CErrReporter(ErrReportingMode Mode = Mode_MessageBox) : m_ReportingMode(Mode)
39 m_szErrBuf[0] = _T(
'\0');
41 CErrReporter(LPCTSTR lpszErrMsg, ErrReportingMode Mode = Mode_MessageBox) : m_ReportingMode(Mode)
46 CErrReporter(ErrReportingMode Mode = Mode_OutputDebugString) : m_ReportingMode(Mode)
48 m_szErrBuf[0] = _T(
'\0');
50 CErrReporter(LPCTSTR lpszErrMsg, ErrReportingMode Mode = Mode_OutputDebugString) : m_ReportingMode(Mode)
64 return m_ReportingMode;
70 return GetErrorDetails(m_szErrBuf, ErrMsgBufSize, dwErrorCode);
105 ZeroMemory(m_szErrBuf,
sizeof(m_szErrBuf));
111 _tcsncpy(m_szErrBuf, lpszErrMsg, ErrMsgBufSize);
112 m_szErrBuf[ErrMsgBufSize] = _T(
'\0');
121 inline operator LPCTSTR()
const
126 inline CErrReporter& operator=(
const CErrReporter& other)
128 m_ReportingMode = other.m_ReportingMode;
137 switch(m_ReportingMode)
139 case Mode_MessageBox: MessageBox(NULL, lpszErrMsg, _T(
"Error"), MB_OK | MB_ICONERROR);
break;
140 case Mode_OutputDebugString: OutputDebugString(lpszErrMsg);
break;
149 inline void ErrorMessage(LPCTSTR lpszErrMsg)
155 #endif // #ifndef _ERROR_H__FC8EA04F_57D6_4002_81BE_F37E1FA54F47_
void Clear()
Clears the Error Message Buffer.
LPCTSTR CollectErrorDetails(DWORD dwErrorCode=GetLastError())
Collects and Formats the Error Message for the last error.
void ReportError() const
Reports the ErrorMessage that was set with SetErrorMessage.
void SetErrorMessage(LPCTSTR lpszErrMsg)
Sets the Error Message.
void ReportError(LPCTSTR lpszErrMsg)
LPCTSTR GetErrorMessage() const
Returns the last Set Error Message.
void ErrorMessage(LPCTSTR lpszErrMsg) const
Displays the given Error Message with MessageBox.
ErrReportingMode & ReportingMode()
Gets/Sets the Error Reporting Mode.
void ReportError(DWORD dwErrorCode)