diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:08:06 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:08:06 +0200 |
commit | fbe76102e941b9f1edaf236788e42678f05fdf9a (patch) | |
tree | f5f538316019fa89be8dc478103490c3a826f3ac /shared/com_error.h | |
parent | 3.8 (diff) | |
download | FreeFileSync-fbe76102e941b9f1edaf236788e42678f05fdf9a.tar.gz FreeFileSync-fbe76102e941b9f1edaf236788e42678f05fdf9a.tar.bz2 FreeFileSync-fbe76102e941b9f1edaf236788e42678f05fdf9a.zip |
3.9
Diffstat (limited to 'shared/com_error.h')
-rw-r--r-- | shared/com_error.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/shared/com_error.h b/shared/com_error.h new file mode 100644 index 00000000..ab365977 --- /dev/null +++ b/shared/com_error.h @@ -0,0 +1,77 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de) * +// ************************************************************************** +// +#ifndef COM_ERROR_HEADER +#define COM_ERROR_HEADER + +#include <string> +#include <cstdio> +#include <comdef.h> + +namespace util +{ +std::wstring generateErrorMsg(const std::wstring& input, HRESULT hr); + + +class ComException +{ +public: + ComException(const std::wstring& message, HRESULT hr = NO_ERROR) + : message_(message), hr_(hr) {} + + std::wstring show() const + { + return hr_ != NO_ERROR ? generateErrorMsg(message_, hr_) : message_; + } + +private: + const std::wstring message_; + const HRESULT hr_; +}; + + + + + + + + + + + + + + + + + + + + + +//################# implementation ##################### +inline +std::wstring numberToHexString(long number) +{ + wchar_t result[100]; + swprintf(result, 100, L"0x%08x", number); + return std::wstring(result); +} + + +inline +std::wstring generateErrorMsg(const std::wstring& input, HRESULT hr) +{ + std::wstring output(input); + output += L" ("; + output += numberToHexString(hr); + output += L": "; + output += _com_error(hr).ErrorMessage(); + output += L")"; + return output; +} +} +#endif //COM_ERROR_HEADER
\ No newline at end of file |