Remove trailing null character from std::string
R=jiayl@webrtc.org Review URL: https://webrtc-codereview.appspot.com/20159004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6923 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
a1ad844229
commit
047abc93a2
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "webrtc/base/win32.h"
|
||||||
#include "webrtc/modules/desktop_capture/desktop_frame_win.h"
|
#include "webrtc/modules/desktop_capture/desktop_frame_win.h"
|
||||||
#include "webrtc/modules/desktop_capture/win/window_capture_utils.h"
|
#include "webrtc/modules/desktop_capture/win/window_capture_utils.h"
|
||||||
#include "webrtc/system_wrappers/interface/logging.h"
|
#include "webrtc/system_wrappers/interface/logging.h"
|
||||||
@ -23,22 +24,6 @@ namespace {
|
|||||||
|
|
||||||
typedef HRESULT (WINAPI *DwmIsCompositionEnabledFunc)(BOOL* enabled);
|
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) {
|
BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
|
||||||
WindowCapturer::WindowList* list =
|
WindowCapturer::WindowList* list =
|
||||||
reinterpret_cast<WindowCapturer::WindowList*>(param);
|
reinterpret_cast<WindowCapturer::WindowList*>(param);
|
||||||
@ -70,7 +55,7 @@ BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
|
|||||||
WCHAR window_title[kTitleLength];
|
WCHAR window_title[kTitleLength];
|
||||||
// Truncate the title if it's longer than kTitleLength.
|
// Truncate the title if it's longer than kTitleLength.
|
||||||
GetWindowText(hwnd, window_title, 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.
|
// Skip windows when we failed to convert the title or it is empty.
|
||||||
if (window.title.empty())
|
if (window.title.empty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user