diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-17 17:00:04 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-17 17:00:04 +0000 |
commit | 3b95b86342778c3a18b70158280332c0601516c9 (patch) | |
tree | 3baeb2e90f6a0160cfe9c6763f13d5d339bb7229 /base/win_util.cc | |
parent | bc9147a10c7287f285ddc1c246cc9d38cd5987c4 (diff) | |
download | chromium_src-3b95b86342778c3a18b70158280332c0601516c9.zip chromium_src-3b95b86342778c3a18b70158280332c0601516c9.tar.gz chromium_src-3b95b86342778c3a18b70158280332c0601516c9.tar.bz2 |
Adds logging to file_util::WriteFile to figure out why writing
bookmarks is failing for some people. As a result of this I moved some
code from common/win_util to base/win_util so that file_util_win could
call it. The only changes to this code are formatting.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2931
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2312 0039d316-1c4b-4281-b951-d872f2087c98
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 - |