Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
Loading...
Searching...
No Matches
hresult.h
Go to the documentation of this file.
1// License: Apache 2.0. See LICENSE file in root directory.
2// Copyright(c) 2021 Intel Corporation. All Rights Reserved.
3
4#pragma once
5#include <string>
6#include <Windows.h>
7#include <functional>
8#include <comdef.h>
9#include <sstream>
11
12namespace utilities {
13namespace hresult {
14
15 inline std::string hr_to_string(HRESULT hr)
16 {
17 _com_error err(hr);
18 std::wstring errorMessage = (err.ErrorMessage()) ? err.ErrorMessage() : L"";
19 std::ostringstream ss;
20 ss << "HResult 0x" << std::hex << hr << ": \"" << string::windows::win_to_utf(errorMessage.data()) << "\"";
21 return ss.str();
22 }
23
24
25#define CHECK_HR_STR( call, hr ) \
26 if( FAILED( hr ) ) \
27 { \
28 std::ostringstream ss; \
29 ss << call << " returned: " << utilities::hresult::hr_to_string( hr ); \
30 std::string descr = ss.str(); \
31 throw std::runtime_error( descr ); \
32 }
33
34
35#define LOG_HR_STR( call, hr ) \
36 if( FAILED( hr ) ) \
37 { \
38 std::ostringstream ss; \
39 ss << call << " returned: " << utilities::hresult::hr_to_string( hr ); \
40 std::string descr = ss.str(); \
41 LOG_DEBUG(descr); \
42 }
43
44#define CHECK_HR( x ) CHECK_HR_STR( #x, x )
45#define LOG_HR( x ) LOG_HR_STR( #x, x )
46
47}
48}
std::string hr_to_string(HRESULT hr)
Definition: hresult.h:15
Definition: stabilized-value.h:12