1 /* 2 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "modules/desktop_capture/win/desktop_capture_utils.h" 12 13 #include "rtc_base/strings/string_builder.h" 14 15 namespace webrtc { 16 namespace desktop_capture { 17 namespace utils { 18 19 // Generates a human-readable string from a COM error. ComErrorToString(const _com_error & error)20std::string ComErrorToString(const _com_error& error) { 21 char buffer[1024]; 22 rtc::SimpleStringBuilder string_builder(buffer); 23 // Use _bstr_t to simplify the wchar to char conversion for ErrorMessage(). 24 _bstr_t error_message(error.ErrorMessage()); 25 string_builder.AppendFormat("HRESULT: 0x%08X, Message: %s", error.Error(), 26 static_cast<const char*>(error_message)); 27 return string_builder.str(); 28 } 29 30 } // namespace utils 31 } // namespace desktop_capture 32 } // namespace webrtc 33