diff --git a/webrtc/modules/desktop_capture/window_capturer_win.cc b/webrtc/modules/desktop_capture/window_capturer_win.cc index 9f19faf273..c6555de4b9 100644 --- a/webrtc/modules/desktop_capture/window_capturer_win.cc +++ b/webrtc/modules/desktop_capture/window_capturer_win.cc @@ -12,6 +12,7 @@ #include +#include "webrtc/base/win32.h" #include "webrtc/modules/desktop_capture/desktop_frame_win.h" #include "webrtc/modules/desktop_capture/win/window_capture_utils.h" #include "webrtc/system_wrappers/interface/logging.h" @@ -23,22 +24,6 @@ namespace { typedef HRESULT (WINAPI *DwmIsCompositionEnabledFunc)(BOOL* enabled); -// Coverts a zero-terminated UTF-16 string to UTF-8. Returns an empty string if -// error occurs. -std::string Utf16ToUtf8(const WCHAR* str) { - int len_utf8 = WideCharToMultiByte(CP_UTF8, 0, str, -1, - NULL, 0, NULL, NULL); - if (len_utf8 <= 0) - return std::string(); - std::string result(len_utf8, '\0'); - int rv = WideCharToMultiByte(CP_UTF8, 0, str, -1, - &*(result.begin()), len_utf8, NULL, NULL); - if (rv != len_utf8) - assert(false); - - return result; -} - BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) { WindowCapturer::WindowList* list = reinterpret_cast(param); @@ -70,7 +55,7 @@ BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) { WCHAR window_title[kTitleLength]; // Truncate the title if it's longer than kTitleLength. GetWindowText(hwnd, window_title, kTitleLength); - window.title = Utf16ToUtf8(window_title); + window.title = rtc::ToUtf8(window_title); // Skip windows when we failed to convert the title or it is empty. if (window.title.empty())