diff options
Diffstat (limited to 'base/win_util.cc')
-rw-r--r-- | base/win_util.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/base/win_util.cc b/base/win_util.cc index b03e06d..38a4133 100644 --- a/base/win_util.cc +++ b/base/win_util.cc @@ -331,6 +331,28 @@ bool UserAccountControlIsEnabled() { return (uac_enabled == 1); } +std::wstring FormatMessage(unsigned messageid) { + wchar_t* string_buffer = NULL; + unsigned string_length = ::FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, messageid, 0, + reinterpret_cast<wchar_t *>(&string_buffer), 0, NULL); + + std::wstring formatted_string; + if (string_buffer) { + formatted_string = string_buffer; + LocalFree(reinterpret_cast<HLOCAL>(string_buffer)); + } else { + // The formating failed. simply convert the message value into a string. + SStringPrintf(&formatted_string, L"message number %d", messageid); + } + return formatted_string; +} + +std::wstring FormatLastWin32Error() { + return FormatMessage(GetLastError()); +} + } // namespace win_util #ifdef _MSC_VER @@ -354,4 +376,3 @@ Also make sure you register the SDK with Visual Studio, by selecting \ menu (see Start - All Programs - Microsoft Windows SDK - \ Visual Studio Registration). #endif - |