mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
common: refactor common library pt2 (#8588)
- remove common lib - split settings, remove common-md - move ipc interop/kb_layout to interop - rename core -> settings, settings -> old_settings - os-detect header-only; interop -> PowerToysInterop - split notifications, move single-use headers where they're used - winstore lib - rename com utils - rename Updating and Telemetry projects - rename core -> settings-ui and remove examples folder - rename settings-ui folder + consisent common/version include
This commit is contained in:
44
src/common/utils/winapi_error.h
Normal file
44
src/common/utils/winapi_error.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <strsafe.h>
|
||||
|
||||
inline std::optional<std::wstring> get_last_error_message(const DWORD dw)
|
||||
{
|
||||
std::optional<std::wstring> message;
|
||||
try
|
||||
{
|
||||
const auto msg = std::system_category().message(dw);
|
||||
message.emplace(begin(msg), end(msg));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
inline void show_last_error_message(const wchar_t* functionName, DWORD dw, const wchar_t* errorTitle)
|
||||
{
|
||||
const auto system_message = get_last_error_message(dw);
|
||||
if (!system_message.has_value())
|
||||
{
|
||||
return;
|
||||
}
|
||||
LPWSTR lpDisplayBuf = (LPWSTR)LocalAlloc(LMEM_ZEROINIT, (system_message->size() + lstrlenW(functionName) + 40) * sizeof(WCHAR));
|
||||
if (lpDisplayBuf != NULL)
|
||||
{
|
||||
StringCchPrintfW(lpDisplayBuf,
|
||||
LocalSize(lpDisplayBuf) / sizeof(WCHAR),
|
||||
L"%s: %s (%d)",
|
||||
functionName,
|
||||
system_message->c_str(),
|
||||
dw);
|
||||
MessageBoxW(NULL, (LPCTSTR)lpDisplayBuf, errorTitle, MB_OK | MB_ICONERROR);
|
||||
LocalFree(lpDisplayBuf);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user