8#ifndef ERRLIB_CPP_H_INCLUDED
9#define ERRLIB_CPP_H_INCLUDED
13const DWORD ERRLIB_CPP_EXCEPTION = 0xC0400002;
33 std::wstring PrintStackTraceImpl(){
36 return std::wstring(buf);
41 void SetMsg(
const std::wstring& msg){_msg=msg;}
43 void SetCode(DWORD code){_code=code;}
45 void SetData(
void* data){_data=data;}
52 Exception():_msg(L
""),_code(ERRLIB_CPP_EXCEPTION),_data(nullptr){
53 RtlCaptureContext(&_context);
54 _stack = this->PrintStackTraceImpl();
60 Exception(
const std::wstring& message):_msg(message),_code(ERRLIB_CPP_EXCEPTION),_data(nullptr){
61 RtlCaptureContext(&_context);
62 _stack = this->PrintStackTraceImpl();
68 Exception(
const std::wstring& message, DWORD code,
void* data):_msg(message),_code(code),_data(data){
69 RtlCaptureContext(&_context);
70 _stack = this->PrintStackTraceImpl();
95 const WCHAR* pChars = _msg.c_str();
96 wcscpy_s(pOutput, cch, pChars);
104 memcpy(pOutput, &_context,
sizeof(CONTEXT));
113 const WCHAR* p = this->_stack.c_str();
114 StringCchCopy(pOutput, cch, p);
135 if (visible) bVisible = TRUE;
136 else bVisible = FALSE;
158 DWORD code = GetLastError();
162 if(localized) fLocalized = TRUE;
163 else fLocalized = FALSE;
176 this->SetCode((DWORD)hr);
#define ErrLib_StackLen
Definition: ErrLib.h:43
ERRLIB_API void __stdcall ErrLib_PrintStack(CONTEXT *ctx, WCHAR *dest, size_t cch)
ERRLIB_API void __stdcall ErrLib_LogExceptionInfo(DWORD dwExcCode, LPCWSTR lpwsMessage, LPCWSTR lpwsStackTrace, BOOL visible)
#define ErrLib_MessageLen
Definition: ErrLib.h:38
Definition: ErrLib_CPP.h:173
static ComException FromHResult(HRESULT hr)
Definition: ErrLib_CPP.h:184
Definition: ErrLib_CPP.h:25
Exception(const std::wstring &message, DWORD code, void *data)
Definition: ErrLib_CPP.h:68
std::wstring PrintStackTrace()
Definition: ErrLib_CPP.h:120
void GetMessageText(WCHAR *pOutput, int cch)
Definition: ErrLib_CPP.h:94
Exception(const std::wstring &message)
Definition: ErrLib_CPP.h:60
void * GetData()
Definition: ErrLib_CPP.h:87
void PrintStackTrace(WCHAR *pOutput, int cch)
Definition: ErrLib_CPP.h:112
DWORD GetCode()
Definition: ErrLib_CPP.h:82
void GetContext(CONTEXT *pOutput)
Definition: ErrLib_CPP.h:103
std::wstring GetMsg()
Definition: ErrLib_CPP.h:76
void Log(bool visible)
Definition: ErrLib_CPP.h:132
Exception()
Definition: ErrLib_CPP.h:52
Definition: ErrLib_CPP.h:145
static WinapiException FromLastError(bool localized)
Definition: ErrLib_CPP.h:157
Definition: ErrLib_CPP.h:19