13 std::string result =
msg;
17 const DWORD MaxStackTrace = 62;
19 void *stackTrace[MaxStackTrace];
20 USHORT numStackTrace = ::CaptureStackBackTrace(0, 62, stackTrace,
nullptr);
24 HANDLE hProc = ::GetCurrentProcess();
26 bret = ::EnumProcessModules(hProc,
nullptr, 0, &neededSize);
28 return std::string(
"<???>");
30 DWORD modCount = neededSize /
sizeof(HMODULE);
31 std::vector<HMODULE> hMods(modCount);
32 bret = ::EnumProcessModules(hProc, hMods.data(), neededSize, &neededSize);
34 return std::string(
"<???>");
36 hMods.resize(neededSize /
sizeof(HMODULE));
39 auto hmoduleComp = [](HMODULE a, HMODULE b) {
40 return reinterpret_cast<uintptr_t
>(a) < reinterpret_cast<uintptr_t>(b);
42 std::sort(hMods.begin(), hMods.end(), hmoduleComp);
45 std::vector<std::string> modNames;
46 modNames.reserve(hMods.size());
47 for (DWORD i = 0; i < modCount; i++) {
49 DWORD ret = ::GetModuleBaseNameA(hProc, hMods[i], baseName,
sizeof(baseName));
51 ::strcpy_s(baseName,
"???");
53 modNames.emplace_back(baseName);
58 for (uint32_t i = 0; i < numStackTrace; i++) {
60 sprintf_s(str,
"%p", stackTrace[i]);
65 auto it = std::upper_bound(hMods.begin(), hMods.end(),
66 (HMODULE)stackTrace[i], hmoduleComp);
67 size_t ind = std::distance(hMods.begin(), it);
69 uintptr_t diff =
reinterpret_cast<uintptr_t
>(stackTrace[i])
70 - reinterpret_cast<uintptr_t>(hMods.at(ind - 1));
71 sprintf_s(str,
"%p", reinterpret_cast<void *>(diff));
75 result += modNames.at(ind - 1);
90 char *lpMsgBuf = NULL;
91 DWORD ret = ::FormatMessageA(
92 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
93 nullptr, code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
94 reinterpret_cast<LPSTR>(&lpMsgBuf), 0,
nullptr);
95 auto del = [](
char *p) {
98 std::unique_ptr<char, decltype(del)> pMsgBuf(lpMsgBuf, del);
99 const char *info = (ret != 0) ? lpMsgBuf :
"<FormatMessageA failed>";
102 std::stringstream ss;
104 ss << std::hex << std::setw(8) << std::setfill(
'0') << code;
105 ss <<
": " << info <<
")";
111 return m_what.c_str();
117 std::stringstream ss;
118 ss << msg <<
" (" << code <<
")";
124 return m_what.c_str();
131 std::stringstream ss;
132 ss << msg <<
" (" << code <<
")";
138 return m_what.c_str();
145 std::stringstream ss;
147 ss << std::hex << std::setw(8) << std::setfill(
'0') << hr;
154 return m_what.c_str();
const char * what() const override
const char * what() const override
OggVorbisError(const std::string &msg, int code)
std::string createStackTraceMsg(const std::string &msg)
Returns (msg + stacktrace) string.
DXError(const std::string &msg, HRESULT hr)
Win32Error(const std::string &msg, DWORD code)
const char * what() const override
char msg[LINE_DATA_SIZE-sizeof(LARGE_INTEGER)-sizeof(uint32_t)]
MmioError(const std::string &msg, UINT code)
const char * what() const override