mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
fix compilation errors
This commit is contained in:
parent
233e97c5e4
commit
5e33a7e58b
@ -55,11 +55,8 @@ struct win32_error : public spdlog_ex
|
||||
{
|
||||
std::string system_message;
|
||||
|
||||
LPSTR format_message_result{};
|
||||
auto format_message_succeeded =
|
||||
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr,
|
||||
error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&format_message_result, 0, nullptr);
|
||||
|
||||
auto fFormatResult = [&system_message](bool format_message_succeeded, void* format_message_result)
|
||||
{
|
||||
if (format_message_succeeded && format_message_result)
|
||||
{
|
||||
system_message = fmt::format(" ({})", format_message_result);
|
||||
@ -69,6 +66,23 @@ struct win32_error : public spdlog_ex
|
||||
{
|
||||
LocalFree((HLOCAL)format_message_result);
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
LPWSTR format_message_result{};
|
||||
auto format_message_succeeded =
|
||||
::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr,
|
||||
error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&format_message_result, 0, nullptr);
|
||||
|
||||
fFormatResult(format_message_succeeded, format_message_result);
|
||||
#else
|
||||
LPSTR format_message_result{};
|
||||
auto format_message_succeeded =
|
||||
::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr,
|
||||
error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&format_message_result, 0, nullptr);
|
||||
|
||||
fFormatResult(format_message_succeeded, format_message_result);
|
||||
#endif
|
||||
|
||||
return fmt::format("{}: {}{}", user_message, error_code, system_message);
|
||||
}
|
||||
@ -203,7 +217,7 @@ private:
|
||||
{
|
||||
if (!hEventLog_)
|
||||
{
|
||||
hEventLog_ = ::RegisterEventSource(nullptr, source_.c_str());
|
||||
hEventLog_ = ::RegisterEventSourceA(nullptr, source_.c_str());
|
||||
if (!hEventLog_ || hEventLog_ == (HANDLE)ERROR_ACCESS_DENIED)
|
||||
{
|
||||
SPDLOG_THROW(internal::win32_error("RegisterEventSource"));
|
||||
@ -218,13 +232,22 @@ protected:
|
||||
{
|
||||
using namespace internal;
|
||||
|
||||
bool succeeded;
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
formatted.push_back('\0');
|
||||
LPCSTR lp_str = static_cast<LPCSTR>(formatted.data());
|
||||
|
||||
auto succeeded = ::ReportEvent(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), event_id_,
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
LPCWSTR lp_str = reinterpret_cast<LPCWSTR>(formatted.data());
|
||||
|
||||
succeeded = ::ReportEventW(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), event_id_,
|
||||
current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr);
|
||||
#else
|
||||
LPCSTR lp_str = reinterpret_cast<LPCSTR>(formatted.data());
|
||||
|
||||
succeeded = ::ReportEventA(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), event_id_,
|
||||
current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr);
|
||||
#endif
|
||||
|
||||
if (!succeeded)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user