From 673f7e56e4fcc0bad05ea880317c1b8921a4fc14 Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Mon, 25 Mar 2019 09:01:02 +0100 Subject: [PATCH] Do not assume /DUNICODE and /D_UNICODE. As a library, WebRTC should not assume UNICODE and _UNICODE to be defined globally. This CL explicitly selects wide character functions and types in order to build WebRTC with /UUNICODE and /U_UNICODE. Bug: None Change-Id: Ie4e2bcb4c5c34aee6f68dc7b5b54b76f088ee3e4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128904 Commit-Queue: Tommi Reviewed-by: Tommi Reviewed-by: Noah Richards Cr-Commit-Position: refs/heads/master@{#27313} --- examples/peerconnection/client/main_wnd.cc | 16 ++++++------- .../audio_device/win/audio_device_core_win.cc | 22 +++++++---------- .../audio_device/win/audio_device_core_win.h | 2 +- .../win/core_audio_utility_win.cc | 3 +-- .../audio_device/win/core_audio_utility_win.h | 4 ++-- .../cropping_window_capturer_win.cc | 4 ++-- modules/desktop_capture/win/desktop.cc | 2 +- .../win/screen_capture_utils.cc | 18 +++++++------- .../win/screen_capturer_win_gdi.cc | 2 +- .../win/screen_capturer_win_magnifier.cc | 24 +++++++++---------- .../win/window_capture_utils.cc | 6 ++--- .../desktop_capture/window_capturer_win.cc | 4 ++-- rtc_base/file_rotating_stream.cc | 22 ++++++++--------- rtc_base/flags.cc | 2 +- rtc_base/platform_file.cc | 14 +++++------ rtc_base/win/windows_version.cc | 22 ++++++++--------- rtc_base/win32.cc | 4 ++-- rtc_base/win32_socket_server.cc | 4 ++-- rtc_base/win32_socket_server.h | 2 +- rtc_base/win32_window.cc | 16 ++++++------- test/testsupport/file_utils.cc | 10 ++++---- test/testsupport/file_utils_override.cc | 2 +- 22 files changed, 100 insertions(+), 105 deletions(-) diff --git a/examples/peerconnection/client/main_wnd.cc b/examples/peerconnection/client/main_wnd.cc index 8edd1e76f3..afafa621b3 100644 --- a/examples/peerconnection/client/main_wnd.cc +++ b/examples/peerconnection/client/main_wnd.cc @@ -34,7 +34,7 @@ void CalculateWindowSizeForText(HWND wnd, size_t* height) { HDC dc = ::GetDC(wnd); RECT text_rc = {0}; - ::DrawText(dc, text, -1, &text_rc, DT_CALCRECT | DT_SINGLELINE); + ::DrawTextW(dc, text, -1, &text_rc, DT_CALCRECT | DT_SINGLELINE); ::ReleaseDC(wnd, dc); RECT client, window; ::GetClientRect(wnd, &client); @@ -347,7 +347,7 @@ void MainWnd::OnDefaultAction() { } } } else { - MessageBoxA(wnd_, "OK!", "Yeah", MB_OK); + ::MessageBoxA(wnd_, "OK!", "Yeah", MB_OK); } } @@ -442,14 +442,14 @@ bool MainWnd::RegisterWindowClass() { if (wnd_class_) return true; - WNDCLASSEX wcex = {sizeof(WNDCLASSEX)}; + WNDCLASSEXW wcex = {sizeof(WNDCLASSEX)}; wcex.style = CS_DBLCLKS; wcex.hInstance = GetModuleHandle(NULL); wcex.hbrBackground = reinterpret_cast(COLOR_WINDOW + 1); wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW); wcex.lpfnWndProc = &WndProc; wcex.lpszClassName = kClassName; - wnd_class_ = ::RegisterClassEx(&wcex); + wnd_class_ = ::RegisterClassExW(&wcex); RTC_DCHECK(wnd_class_ != 0); return wnd_class_ != 0; } @@ -464,9 +464,9 @@ void MainWnd::CreateChildWindow(HWND* wnd, // Child windows are invisible at first, and shown after being resized. DWORD style = WS_CHILD | control_style; - *wnd = ::CreateWindowEx(ex_style, class_name, L"", style, 100, 100, 100, 100, - wnd_, reinterpret_cast(id), - GetModuleHandle(NULL), NULL); + *wnd = ::CreateWindowExW(ex_style, class_name, L"", style, 100, 100, 100, 100, + wnd_, reinterpret_cast(id), + GetModuleHandle(NULL), NULL); RTC_DCHECK(::IsWindow(*wnd) != FALSE); ::SendMessage(*wnd, WM_SETFONT, reinterpret_cast(GetDefaultFont()), TRUE); @@ -522,7 +522,7 @@ void MainWnd::LayoutConnectUI(bool show) { static_cast(windows[i].height), TRUE); x += kSeparator + windows[i].width; if (windows[i].text[0] != 'X') - ::SetWindowText(windows[i].wnd, windows[i].text); + ::SetWindowTextW(windows[i].wnd, windows[i].text); ::ShowWindow(windows[i].wnd, SW_SHOWNA); } } else { diff --git a/modules/audio_device/win/audio_device_core_win.cc b/modules/audio_device/win/audio_device_core_win.cc index 11ba5c3677..0585a710d2 100644 --- a/modules/audio_device/win/audio_device_core_win.cc +++ b/modules/audio_device/win/audio_device_core_win.cc @@ -179,8 +179,8 @@ bool AudioDeviceWindowsCore::CoreAudioIsSupported() { bool coreAudioIsSupported(false); HRESULT hr(S_OK); - TCHAR buf[MAXERRORLENGTH]; - TCHAR errorText[MAXERRORLENGTH]; + wchar_t buf[MAXERRORLENGTH]; + wchar_t errorText[MAXERRORLENGTH]; // 1) Check if Windows version is Vista SP1 or later. // @@ -289,8 +289,8 @@ bool AudioDeviceWindowsCore::CoreAudioIsSupported() { errorText[messageLength - 1] = '\0'; } - StringCchPrintf(buf, MAXERRORLENGTH, TEXT("Error details: ")); - StringCchCat(buf, MAXERRORLENGTH, errorText); + StringCchPrintfW(buf, MAXERRORLENGTH, L"Error details: "); + StringCchCatW(buf, MAXERRORLENGTH, errorText); RTC_LOG(LS_VERBOSE) << buf; } else { MMDeviceIsAvailable = true; @@ -4160,8 +4160,8 @@ Exit: // ---------------------------------------------------------------------------- void AudioDeviceWindowsCore::_TraceCOMError(HRESULT hr) const { - TCHAR buf[MAXERRORLENGTH]; - TCHAR errorText[MAXERRORLENGTH]; + wchar_t buf[MAXERRORLENGTH]; + wchar_t errorText[MAXERRORLENGTH]; const DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; @@ -4181,8 +4181,8 @@ void AudioDeviceWindowsCore::_TraceCOMError(HRESULT hr) const { } RTC_LOG(LS_ERROR) << "Core Audio method failed (hr=" << hr << ")"; - StringCchPrintf(buf, MAXERRORLENGTH, TEXT("Error details: ")); - StringCchCat(buf, MAXERRORLENGTH, errorText); + StringCchPrintfW(buf, MAXERRORLENGTH, L"Error details: "); + StringCchCatW(buf, MAXERRORLENGTH, errorText); RTC_LOG(LS_ERROR) << WideToUTF8(buf); } @@ -4190,8 +4190,7 @@ void AudioDeviceWindowsCore::_TraceCOMError(HRESULT hr) const { // WideToUTF8 // ---------------------------------------------------------------------------- -char* AudioDeviceWindowsCore::WideToUTF8(const TCHAR* src) const { -#ifdef UNICODE +char* AudioDeviceWindowsCore::WideToUTF8(const wchar_t* src) const { const size_t kStrLen = sizeof(_str); memset(_str, 0, kStrLen); // Get required size (in bytes) to be able to complete the conversion. @@ -4203,9 +4202,6 @@ char* AudioDeviceWindowsCore::WideToUTF8(const TCHAR* src) const { memset(_str, 0, kStrLen); } return _str; -#else - return const_cast(src); -#endif } bool AudioDeviceWindowsCore::KeyPressed() const { diff --git a/modules/audio_device/win/audio_device_core_win.h b/modules/audio_device/win/audio_device_core_win.h index 3bc1b0cdda..6dd30c80f4 100644 --- a/modules/audio_device/win/audio_device_core_win.h +++ b/modules/audio_device/win/audio_device_core_win.h @@ -235,7 +235,7 @@ class AudioDeviceWindowsCore : public AudioDeviceGeneric { // Converts from wide-char to UTF-8 if UNICODE is defined. // Does nothing if UNICODE is undefined. - char* WideToUTF8(const TCHAR* src) const; + char* WideToUTF8(const wchar_t* src) const; int32_t InitRecordingDMO(); diff --git a/modules/audio_device/win/core_audio_utility_win.cc b/modules/audio_device/win/core_audio_utility_win.cc index 83ac8aa0e0..3a00d4898b 100644 --- a/modules/audio_device/win/core_audio_utility_win.cc +++ b/modules/audio_device/win/core_audio_utility_win.cc @@ -1386,8 +1386,7 @@ double FramesToMilliseconds(uint32_t num_frames, uint16_t sample_rate) { std::string ErrorToString(const _com_error& error) { char ss_buf[1024]; rtc::SimpleStringBuilder ss(ss_buf); - ss.AppendFormat("%s (0x%08X)", rtc::ToUtf8(error.ErrorMessage()).c_str(), - error.Error()); + ss.AppendFormat("(HRESULT: 0x%08X)", error.Error()); return ss.str(); } diff --git a/modules/audio_device/win/core_audio_utility_win.h b/modules/audio_device/win/core_audio_utility_win.h index aeb89400ac..1307542b35 100644 --- a/modules/audio_device/win/core_audio_utility_win.h +++ b/modules/audio_device/win/core_audio_utility_win.h @@ -81,11 +81,11 @@ class ScopedMMCSSRegistration { } } - explicit ScopedMMCSSRegistration(const TCHAR* task_name) { + explicit ScopedMMCSSRegistration(const wchar_t* task_name) { RTC_DLOG(INFO) << "ScopedMMCSSRegistration: " << rtc::ToUtf8(task_name); // Register the calling thread with MMCSS for the supplied |task_name|. DWORD mmcss_task_index = 0; - mmcss_handle_ = AvSetMmThreadCharacteristics(task_name, &mmcss_task_index); + mmcss_handle_ = AvSetMmThreadCharacteristicsW(task_name, &mmcss_task_index); if (mmcss_handle_ == nullptr) { RTC_LOG(LS_ERROR) << "Failed to enable MMCSS on this thread: " << GetLastError(); diff --git a/modules/desktop_capture/cropping_window_capturer_win.cc b/modules/desktop_capture/cropping_window_capturer_win.cc index dc9ceb8115..8d7e9a2707 100644 --- a/modules/desktop_capture/cropping_window_capturer_win.cc +++ b/modules/desktop_capture/cropping_window_capturer_win.cc @@ -36,7 +36,7 @@ struct TopWindowVerifierContext { is_top_window(false) { RTC_DCHECK_NE(selected_window, excluded_window); - GetWindowText(selected_window, selected_window_title, kTitleLength); + GetWindowTextW(selected_window, selected_window_title, kTitleLength); GetWindowThreadProcessId(selected_window, &selected_window_process_id); } @@ -105,7 +105,7 @@ BOOL CALLBACK TopWindowVerifier(HWND hwnd, LPARAM param) { // menu of the child-window is covering the main window. See // https://bugs.chromium.org/p/webrtc/issues/detail?id=8062 for details. WCHAR window_title[kTitleLength]; - GetWindowText(hwnd, window_title, kTitleLength); + GetWindowTextW(hwnd, window_title, kTitleLength); if (wcsnlen_s(window_title, kTitleLength) == 0 || wcscmp(window_title, context->selected_window_title) == 0) { DWORD enumerated_window_process_id; diff --git a/modules/desktop_capture/win/desktop.cc b/modules/desktop_capture/win/desktop.cc index 459b6fe3be..4fdf266a46 100644 --- a/modules/desktop_capture/win/desktop.cc +++ b/modules/desktop_capture/win/desktop.cc @@ -75,7 +75,7 @@ Desktop* Desktop::GetDesktop(const WCHAR* desktop_name) { DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS | DESKTOP_SWITCHDESKTOP | GENERIC_WRITE; - HDESK desktop = OpenDesktop(desktop_name, 0, FALSE, desired_access); + HDESK desktop = OpenDesktopW(desktop_name, 0, FALSE, desired_access); if (desktop == NULL) { RTC_LOG(LS_ERROR) << "Failed to open the desktop '" << desktop_name << "': " << GetLastError(); diff --git a/modules/desktop_capture/win/screen_capture_utils.cc b/modules/desktop_capture/win/screen_capture_utils.cc index 6ab9738860..95f6d92059 100644 --- a/modules/desktop_capture/win/screen_capture_utils.cc +++ b/modules/desktop_capture/win/screen_capture_utils.cc @@ -31,9 +31,9 @@ bool GetScreenList(DesktopCapturer::SourceList* screens, BOOL enum_result = TRUE; for (int device_index = 0;; ++device_index) { - DISPLAY_DEVICE device; + DISPLAY_DEVICEW device; device.cb = sizeof(device); - enum_result = EnumDisplayDevices(NULL, device_index, &device, 0); + enum_result = EnumDisplayDevicesW(NULL, device_index, &device, 0); // |enum_result| is 0 if we have enumerated all devices. if (!enum_result) @@ -57,9 +57,9 @@ bool IsScreenValid(DesktopCapturer::SourceId screen, std::wstring* device_key) { return true; } - DISPLAY_DEVICE device; + DISPLAY_DEVICEW device; device.cb = sizeof(device); - BOOL enum_result = EnumDisplayDevices(NULL, screen, &device, 0); + BOOL enum_result = EnumDisplayDevicesW(NULL, screen, &device, 0); if (enum_result) *device_key = device.DeviceKey; @@ -79,9 +79,9 @@ DesktopRect GetScreenRect(DesktopCapturer::SourceId screen, return GetFullscreenRect(); } - DISPLAY_DEVICE device; + DISPLAY_DEVICEW device; device.cb = sizeof(device); - BOOL result = EnumDisplayDevices(NULL, screen, &device, 0); + BOOL result = EnumDisplayDevicesW(NULL, screen, &device, 0); if (!result) return DesktopRect(); @@ -92,11 +92,11 @@ DesktopRect GetScreenRect(DesktopCapturer::SourceId screen, if (device_key != device.DeviceKey) return DesktopRect(); - DEVMODE device_mode; + DEVMODEW device_mode; device_mode.dmSize = sizeof(device_mode); device_mode.dmDriverExtra = 0; - result = EnumDisplaySettingsEx(device.DeviceName, ENUM_CURRENT_SETTINGS, - &device_mode, 0); + result = EnumDisplaySettingsExW(device.DeviceName, ENUM_CURRENT_SETTINGS, + &device_mode, 0); if (!result) return DesktopRect(); diff --git a/modules/desktop_capture/win/screen_capturer_win_gdi.cc b/modules/desktop_capture/win/screen_capturer_win_gdi.cc index 866386c782..bf6cb162a0 100644 --- a/modules/desktop_capture/win/screen_capturer_win_gdi.cc +++ b/modules/desktop_capture/win/screen_capturer_win_gdi.cc @@ -42,7 +42,7 @@ ScreenCapturerWinGdi::ScreenCapturerWinGdi( if (options.disable_effects()) { // Load dwmapi.dll dynamically since it is not available on XP. if (!dwmapi_library_) - dwmapi_library_ = LoadLibrary(kDwmapiLibraryName); + dwmapi_library_ = LoadLibraryW(kDwmapiLibraryName); if (dwmapi_library_) { composition_func_ = reinterpret_cast( diff --git a/modules/desktop_capture/win/screen_capturer_win_magnifier.cc b/modules/desktop_capture/win/screen_capturer_win_magnifier.cc index 891717c146..8293ae51b7 100644 --- a/modules/desktop_capture/win/screen_capturer_win_magnifier.cc +++ b/modules/desktop_capture/win/screen_capturer_win_magnifier.cc @@ -37,10 +37,10 @@ DWORD GetTlsIndex() { // kMagnifierWindowClass has to be "Magnifier" according to the Magnification // API. The other strings can be anything. -static LPCTSTR kMagnifierHostClass = L"ScreenCapturerWinMagnifierHost"; -static LPCTSTR kHostWindowName = L"MagnifierHost"; -static LPCTSTR kMagnifierWindowClass = L"Magnifier"; -static LPCTSTR kMagnifierWindowName = L"MagnifierWindow"; +static wchar_t kMagnifierHostClass[] = L"ScreenCapturerWinMagnifierHost"; +static wchar_t kHostWindowName[] = L"MagnifierHost"; +static wchar_t kMagnifierWindowClass[] = L"Magnifier"; +static wchar_t kMagnifierWindowName[] = L"MagnifierWindow"; ScreenCapturerWinMagnifier::ScreenCapturerWinMagnifier() = default; ScreenCapturerWinMagnifier::~ScreenCapturerWinMagnifier() { @@ -209,7 +209,7 @@ bool ScreenCapturerWinMagnifier::InitializeMagnifier() { desktop_dc_ = GetDC(nullptr); - mag_lib_handle_ = LoadLibrary(L"Magnification.dll"); + mag_lib_handle_ = LoadLibraryW(L"Magnification.dll"); if (!mag_lib_handle_) return false; @@ -255,7 +255,7 @@ bool ScreenCapturerWinMagnifier::InitializeMagnifier() { // Register the host window class. See the MSDN documentation of the // Magnification API for more infomation. - WNDCLASSEX wcex = {}; + WNDCLASSEXW wcex = {}; wcex.cbSize = sizeof(WNDCLASSEX); wcex.lpfnWndProc = &DefWindowProc; wcex.hInstance = hInstance; @@ -263,12 +263,12 @@ bool ScreenCapturerWinMagnifier::InitializeMagnifier() { wcex.lpszClassName = kMagnifierHostClass; // Ignore the error which may happen when the class is already registered. - RegisterClassEx(&wcex); + RegisterClassExW(&wcex); // Create the host window. host_window_ = - CreateWindowEx(WS_EX_LAYERED, kMagnifierHostClass, kHostWindowName, 0, 0, - 0, 0, 0, nullptr, nullptr, hInstance, nullptr); + CreateWindowExW(WS_EX_LAYERED, kMagnifierHostClass, kHostWindowName, 0, 0, + 0, 0, 0, nullptr, nullptr, hInstance, nullptr); if (!host_window_) { mag_uninitialize_func_(); RTC_LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: " @@ -278,9 +278,9 @@ bool ScreenCapturerWinMagnifier::InitializeMagnifier() { } // Create the magnifier control. - magnifier_window_ = CreateWindow(kMagnifierWindowClass, kMagnifierWindowName, - WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, - host_window_, nullptr, hInstance, nullptr); + magnifier_window_ = CreateWindowW(kMagnifierWindowClass, kMagnifierWindowName, + WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, + host_window_, nullptr, hInstance, nullptr); if (!magnifier_window_) { mag_uninitialize_func_(); RTC_LOG_F(LS_WARNING) << "Failed to initialize ScreenCapturerWinMagnifier: " diff --git a/modules/desktop_capture/win/window_capture_utils.cc b/modules/desktop_capture/win/window_capture_utils.cc index f2e9052482..845463372d 100644 --- a/modules/desktop_capture/win/window_capture_utils.cc +++ b/modules/desktop_capture/win/window_capture_utils.cc @@ -142,7 +142,7 @@ WindowCaptureHelperWin::WindowCaptureHelperWin() func_(nullptr), virtual_desktop_manager_(nullptr) { // Try to load dwmapi.dll dynamically since it is not available on XP. - dwmapi_library_ = LoadLibrary(L"dwmapi.dll"); + dwmapi_library_ = LoadLibraryW(L"dwmapi.dll"); if (dwmapi_library_) { func_ = reinterpret_cast( GetProcAddress(dwmapi_library_, "DwmIsCompositionEnabled")); @@ -178,14 +178,14 @@ bool WindowCaptureHelperWin::IsAeroEnabled() { bool WindowCaptureHelperWin::IsWindowChromeNotification(HWND hwnd) { const size_t kTitleLength = 32; WCHAR window_title[kTitleLength]; - GetWindowText(hwnd, window_title, kTitleLength); + GetWindowTextW(hwnd, window_title, kTitleLength); if (wcsnlen_s(window_title, kTitleLength) != 0) { return false; } const size_t kClassLength = 256; WCHAR class_name[kClassLength]; - const int class_name_length = GetClassName(hwnd, class_name, kClassLength); + const int class_name_length = GetClassNameW(hwnd, class_name, kClassLength); RTC_DCHECK(class_name_length) << "Error retrieving the application's class name"; if (wcsncmp(class_name, kChromeWindowClassPrefix, diff --git a/modules/desktop_capture/window_capturer_win.cc b/modules/desktop_capture/window_capturer_win.cc index 52b2bac83e..4ab1feb3ed 100644 --- a/modules/desktop_capture/window_capturer_win.cc +++ b/modules/desktop_capture/window_capturer_win.cc @@ -53,7 +53,7 @@ BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) { // Skip the Program Manager window and the Start button. const size_t kClassLength = 256; WCHAR class_name[kClassLength]; - const int class_name_length = GetClassName(hwnd, class_name, kClassLength); + const int class_name_length = GetClassNameW(hwnd, class_name, kClassLength); RTC_DCHECK(class_name_length) << "Error retrieving the application's class name"; @@ -79,7 +79,7 @@ BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) { const size_t kTitleLength = 500; WCHAR window_title[kTitleLength]; // Truncate the title if it's longer than kTitleLength. - GetWindowText(hwnd, window_title, kTitleLength); + GetWindowTextW(hwnd, window_title, kTitleLength); window.title = rtc::ToUtf8(window_title); // Skip windows when we failed to convert the title or it is empty. diff --git a/rtc_base/file_rotating_stream.cc b/rtc_base/file_rotating_stream.cc index 80c9edf7c8..98e817b9a7 100644 --- a/rtc_base/file_rotating_stream.cc +++ b/rtc_base/file_rotating_stream.cc @@ -62,41 +62,41 @@ std::string AddTrailingPathDelimiterIfNeeded(std::string directory) { std::vector GetFilesWithPrefix(const std::string& directory, const std::string& prefix) { RTC_DCHECK(absl::EndsWith(directory, "\\")); - WIN32_FIND_DATA data; + WIN32_FIND_DATAW data; HANDLE handle; - handle = ::FindFirstFile(ToUtf16(directory + prefix + '*').c_str(), &data); + handle = ::FindFirstFileW(ToUtf16(directory + prefix + '*').c_str(), &data); if (handle == INVALID_HANDLE_VALUE) return {}; std::vector file_list; do { file_list.emplace_back(directory + ToUtf8(data.cFileName)); - } while (::FindNextFile(handle, &data) == TRUE); + } while (::FindNextFileW(handle, &data) == TRUE); ::FindClose(handle); return file_list; } bool DeleteFile(const std::string& file) { - return ::DeleteFile(ToUtf16(file).c_str()) != 0; + return ::DeleteFileW(ToUtf16(file).c_str()) != 0; } bool MoveFile(const std::string& old_file, const std::string& new_file) { - return ::MoveFile(ToUtf16(old_file).c_str(), ToUtf16(new_file).c_str()) != 0; + return ::MoveFileW(ToUtf16(old_file).c_str(), ToUtf16(new_file).c_str()) != 0; } bool IsFile(const std::string& file) { WIN32_FILE_ATTRIBUTE_DATA data = {0}; - if (0 == ::GetFileAttributesEx(ToUtf16(file).c_str(), GetFileExInfoStandard, - &data)) + if (0 == ::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard, + &data)) return false; return (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0; } bool IsFolder(const std::string& file) { WIN32_FILE_ATTRIBUTE_DATA data = {0}; - if (0 == ::GetFileAttributesEx(ToUtf16(file).c_str(), GetFileExInfoStandard, - &data)) + if (0 == ::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard, + &data)) return false; return (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY; @@ -104,8 +104,8 @@ bool IsFolder(const std::string& file) { absl::optional GetFileSize(const std::string& file) { WIN32_FILE_ATTRIBUTE_DATA data = {0}; - if (::GetFileAttributesEx(ToUtf16(file).c_str(), GetFileExInfoStandard, - &data) == 0) + if (::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard, + &data) == 0) return absl::nullopt; return data.nFileSizeLow; } diff --git a/rtc_base/flags.cc b/rtc_base/flags.cc index 6a87eb4b7b..3bb0459581 100644 --- a/rtc_base/flags.cc +++ b/rtc_base/flags.cc @@ -292,7 +292,7 @@ void FlagList::Register(Flag* flag) { #if defined(WEBRTC_WIN) WindowsCommandLineArguments::WindowsCommandLineArguments() { // start by getting the command line. - LPTSTR command_line = ::GetCommandLine(); + LPCWSTR command_line = ::GetCommandLineW(); // now, convert it to a list of wide char strings. LPWSTR* wide_argv = ::CommandLineToArgvW(command_line, &argc_); // now allocate an array big enough to hold that many string pointers. diff --git a/rtc_base/platform_file.cc b/rtc_base/platform_file.cc index f9317d304c..e4f8b5e492 100644 --- a/rtc_base/platform_file.cc +++ b/rtc_base/platform_file.cc @@ -44,22 +44,22 @@ bool ClosePlatformFile(PlatformFile file) { } bool RemoveFile(const std::string& path) { - return ::DeleteFile(ToUtf16(path).c_str()) != 0; + return ::DeleteFileW(ToUtf16(path).c_str()) != 0; } PlatformFile OpenPlatformFile(const std::string& path) { - return ::CreateFile(ToUtf16(path).c_str(), GENERIC_READ | GENERIC_WRITE, 0, - nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + return ::CreateFileW(ToUtf16(path).c_str(), GENERIC_READ | GENERIC_WRITE, 0, + nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); } PlatformFile OpenPlatformFileReadOnly(const std::string& path) { - return ::CreateFile(ToUtf16(path).c_str(), GENERIC_READ, FILE_SHARE_READ, - nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + return ::CreateFileW(ToUtf16(path).c_str(), GENERIC_READ, FILE_SHARE_READ, + nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); } PlatformFile CreatePlatformFile(const std::string& path) { - return ::CreateFile(ToUtf16(path).c_str(), GENERIC_READ | GENERIC_WRITE, 0, - nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + return ::CreateFileW(ToUtf16(path).c_str(), GENERIC_READ | GENERIC_WRITE, 0, + nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); } #else // defined(WEBRTC_WIN) diff --git a/rtc_base/win/windows_version.cc b/rtc_base/win/windows_version.cc index 8b007ccfbf..a1ba2c6465 100644 --- a/rtc_base/win/windows_version.cc +++ b/rtc_base/win/windows_version.cc @@ -64,8 +64,8 @@ class RegKey { RTC_DCHECK(rootkey && subkey && access && disposition); HKEY subhkey = NULL; LONG result = - ::RegCreateKeyEx(rootkey, subkey, 0, NULL, REG_OPTION_NON_VOLATILE, - access, NULL, &subhkey, disposition); + ::RegCreateKeyExW(rootkey, subkey, 0, NULL, REG_OPTION_NON_VOLATILE, + access, NULL, &subhkey, disposition); if (result == ERROR_SUCCESS) { Close(); key_ = subhkey; @@ -80,7 +80,7 @@ class RegKey { RTC_DCHECK(rootkey && subkey && access); HKEY subhkey = NULL; - LONG result = ::RegOpenKeyEx(rootkey, subkey, 0, access, &subhkey); + LONG result = ::RegOpenKeyExW(rootkey, subkey, 0, access, &subhkey); if (result == ERROR_SUCCESS) { Close(); key_ = subhkey; @@ -131,7 +131,7 @@ class RegKey { } else if (type == REG_EXPAND_SZ) { wchar_t expanded[kMaxStringLength]; size = - ::ExpandEnvironmentStrings(raw_value, expanded, kMaxStringLength); + ::ExpandEnvironmentStringsW(raw_value, expanded, kMaxStringLength); // Success: returns the number of wchar_t's copied // Fail: buffer too small, returns the size required // Fail: other, returns 0 @@ -153,8 +153,8 @@ class RegKey { void* data, DWORD* dsize, DWORD* dtype) const { - LONG result = RegQueryValueEx(key_, name, 0, dtype, - reinterpret_cast(data), dsize); + LONG result = RegQueryValueExW(key_, name, 0, dtype, + reinterpret_cast(data), dsize); return result; } @@ -261,14 +261,14 @@ OSInfo::OSInfo() : version_(VERSION_PRE_XP), architecture_(OTHER_ARCHITECTURE), wow64_status_(GetWOW64StatusForProcess(GetCurrentProcess())) { - OSVERSIONINFOEX version_info = {sizeof version_info}; + OSVERSIONINFOEXW version_info = {sizeof version_info}; // Applications not manifested for Windows 8.1 or Windows 10 will return the // Windows 8 OS version value (6.2). Once an application is manifested for a // given operating system version, GetVersionEx() will always return the // version that the application is manifested for in future releases. // https://docs.microsoft.com/en-us/windows/desktop/SysInfo/targeting-your-application-at-windows-8-1. // https://www.codeproject.com/Articles/678606/Part-Overcoming-Windows-s-deprecation-of-GetVe. - ::GetVersionEx(reinterpret_cast(&version_info)); + ::GetVersionExW(reinterpret_cast(&version_info)); version_number_.major = version_info.dwMajorVersion; version_number_.minor = version_info.dwMinorVersion; version_number_.build = version_info.dwBuildNumber; @@ -301,8 +301,8 @@ OSInfo::OSInfo() if (version_info.dwMajorVersion == 6 || version_info.dwMajorVersion == 10) { // Only present on Vista+. - get_product_info = reinterpret_cast( - ::GetProcAddress(::GetModuleHandle(L"kernel32.dll"), "GetProductInfo")); + get_product_info = reinterpret_cast(::GetProcAddress( + ::GetModuleHandleW(L"kernel32.dll"), "GetProductInfo")); get_product_info(version_info.dwMajorVersion, version_info.dwMinorVersion, 0, 0, &os_type); @@ -404,7 +404,7 @@ OSInfo::WOW64Status OSInfo::GetWOW64StatusForProcess(HANDLE process_handle) { #else typedef BOOL(WINAPI * IsWow64ProcessFunc)(HANDLE, PBOOL); IsWow64ProcessFunc is_wow64_process = reinterpret_cast( - GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); + GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "IsWow64Process")); if (!is_wow64_process) return WOW64_DISABLED; if (!(*is_wow64_process)(process_handle, &is_wow64)) diff --git a/rtc_base/win32.cc b/rtc_base/win32.cc index b5a2611914..acc3d331de 100644 --- a/rtc_base/win32.cc +++ b/rtc_base/win32.cc @@ -337,14 +337,14 @@ bool Utf8ToWindowsFilename(const std::string& utf8, std::wstring* filename) { filename->assign(wfilename); #else // Convert to complete filename - DWORD full_len = ::GetFullPathName(wfilename, 0, nullptr, nullptr); + DWORD full_len = ::GetFullPathNameW(wfilename, 0, nullptr, nullptr); if (0 == full_len) { return false; } wchar_t* filepart = nullptr; wchar_t* full_filename = STACK_ARRAY(wchar_t, full_len + 6); wchar_t* start = full_filename + 6; - if (0 == ::GetFullPathName(wfilename, full_len, start, &filepart)) { + if (0 == ::GetFullPathNameW(wfilename, full_len, start, &filepart)) { return false; } // Add long-path prefix diff --git a/rtc_base/win32_socket_server.cc b/rtc_base/win32_socket_server.cc index 389b76b352..585cd19816 100644 --- a/rtc_base/win32_socket_server.cc +++ b/rtc_base/win32_socket_server.cc @@ -666,12 +666,12 @@ void Win32Socket::OnDnsNotify(HANDLE task, int error) { /////////////////////////////////////////////////////////////////////////////// static UINT s_wm_wakeup_id = 0; -const TCHAR Win32SocketServer::kWindowName[] = L"libjingle Message Window"; +const wchar_t Win32SocketServer::kWindowName[] = L"libjingle Message Window"; Win32SocketServer::Win32SocketServer() : wnd_(this), posted_(false), hdlg_(nullptr) { if (s_wm_wakeup_id == 0) - s_wm_wakeup_id = RegisterWindowMessage(L"WM_WAKEUP"); + s_wm_wakeup_id = RegisterWindowMessageW(L"WM_WAKEUP"); if (!wnd_.Create(nullptr, kWindowName, 0, 0, 0, 0, 0, 0)) { RTC_LOG_GLE(LS_ERROR) << "Failed to create message window."; } diff --git a/rtc_base/win32_socket_server.h b/rtc_base/win32_socket_server.h index 37515d92ff..5c209d96d4 100644 --- a/rtc_base/win32_socket_server.h +++ b/rtc_base/win32_socket_server.h @@ -121,7 +121,7 @@ class Win32SocketServer : public SocketServer { Win32SocketServer* ss_; }; - static const TCHAR kWindowName[]; + static const wchar_t kWindowName[]; MessageQueue* message_queue_; MessageWindow wnd_; CriticalSection cs_; diff --git a/rtc_base/win32_window.cc b/rtc_base/win32_window.cc index fc7b4c3099..b0eb6053bd 100644 --- a/rtc_base/win32_window.cc +++ b/rtc_base/win32_window.cc @@ -42,29 +42,29 @@ bool Win32Window::Create(HWND parent, } if (!window_class_) { - if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | - GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - reinterpret_cast(&Win32Window::WndProc), - &instance_)) { + if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast(&Win32Window::WndProc), + &instance_)) { RTC_LOG_GLE(LS_ERROR) << "GetModuleHandleEx failed"; return false; } // Class not registered, register it. - WNDCLASSEX wcex; + WNDCLASSEXW wcex; memset(&wcex, 0, sizeof(wcex)); wcex.cbSize = sizeof(wcex); wcex.hInstance = instance_; wcex.lpfnWndProc = &Win32Window::WndProc; wcex.lpszClassName = kWindowBaseClassName; - window_class_ = ::RegisterClassEx(&wcex); + window_class_ = ::RegisterClassExW(&wcex); if (!window_class_) { RTC_LOG_GLE(LS_ERROR) << "RegisterClassEx failed"; return false; } } - wnd_ = ::CreateWindowEx(exstyle, kWindowBaseClassName, title, style, x, y, cx, - cy, parent, nullptr, instance_, this); + wnd_ = ::CreateWindowExW(exstyle, kWindowBaseClassName, title, style, x, y, + cx, cy, parent, nullptr, instance_, this); return (nullptr != wnd_); } diff --git a/test/testsupport/file_utils.cc b/test/testsupport/file_utils.cc index 45b2bc2618..b3ef0eb732 100644 --- a/test/testsupport/file_utils.cc +++ b/test/testsupport/file_utils.cc @@ -104,8 +104,8 @@ std::string WorkingDir() { std::string TempFilename(const std::string& dir, const std::string& prefix) { #ifdef WIN32 wchar_t filename[MAX_PATH]; - if (::GetTempFileName(rtc::ToUtf16(dir).c_str(), rtc::ToUtf16(prefix).c_str(), - 0, filename) != 0) + if (::GetTempFileNameW(rtc::ToUtf16(dir).c_str(), + rtc::ToUtf16(prefix).c_str(), 0, filename) != 0) return rtc::ToUtf8(filename); assert(false); return ""; @@ -143,8 +143,8 @@ absl::optional> ReadDirectory(std::string path) { path += '\\'; // Init. - WIN32_FIND_DATA data; - HANDLE handle = ::FindFirstFile(rtc::ToUtf16(path + '*').c_str(), &data); + WIN32_FIND_DATAW data; + HANDLE handle = ::FindFirstFileW(rtc::ToUtf16(path + '*').c_str(), &data); if (handle == INVALID_HANDLE_VALUE) return absl::optional>(); @@ -154,7 +154,7 @@ absl::optional> ReadDirectory(std::string path) { const std::string name = rtc::ToUtf8(data.cFileName); if (name != "." && name != "..") found_entries.emplace_back(path + name); - } while (::FindNextFile(handle, &data) == TRUE); + } while (::FindNextFileW(handle, &data) == TRUE); // Release resources. if (handle != INVALID_HANDLE_VALUE) diff --git a/test/testsupport/file_utils_override.cc b/test/testsupport/file_utils_override.cc index e2c2c0f00c..b50c437325 100644 --- a/test/testsupport/file_utils_override.cc +++ b/test/testsupport/file_utils_override.cc @@ -99,7 +99,7 @@ absl::optional ProjectRootPath() { #elif defined(WEBRTC_WIN) wchar_t buf[MAX_PATH]; buf[0] = 0; - if (GetModuleFileName(NULL, buf, MAX_PATH) == 0) + if (GetModuleFileNameW(NULL, buf, MAX_PATH) == 0) return absl::nullopt; std::string exe_path = rtc::ToUtf8(std::wstring(buf));