tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

desktop_capture_utils.cc (1286B)


      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 <string>
     14 
     15 #include <cstdio>
     16 #include <cstdlib>
     17 #include "stringapiset.h"
     18 
     19 namespace webrtc {
     20 namespace desktop_capture {
     21 namespace utils {
     22 
     23 // Generates a human-readable string from a COM error.
     24 std::string ComErrorToString(const _com_error& error) {
     25  char buffer[1024];
     26  webrtc::SimpleStringBuilder string_builder(buffer);
     27  string_builder.AppendFormat("HRESULT: 0x%08X, Message: ", error.Error());
     28 #ifdef _UNICODE
     29  WideCharToMultiByte(CP_UTF8, 0, error.ErrorMessage(), -1,
     30                      buffer + string_builder.size(),
     31                      sizeof(buffer) - string_builder.size(), nullptr, nullptr);
     32  buffer[sizeof(buffer) - 1] = 0;
     33 #else
     34  string_builder << error.ErrorMessage();
     35 #endif
     36  return buffer;
     37 }
     38 
     39 }  // namespace utils
     40 }  // namespace desktop_capture
     41 }  // namespace webrtc