// ************************************************************************** // * 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-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef COM_ERROR_HEADER #define COM_ERROR_HEADER #include #include #include 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: ComException(const ComException&); ComException& operator=(const ComException&); 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