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 <tommi@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Noah Richards <noahric@chromium.org>
Cr-Commit-Position: refs/heads/master@{#27313}
This commit is contained in:
Mirko Bonadei 2019-03-25 09:01:02 +01:00 committed by Commit Bot
parent 24923e8cfa
commit 673f7e56e4
22 changed files with 100 additions and 105 deletions

View file

@ -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<HBRUSH>(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,7 +464,7 @@ 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 = ::CreateWindowExW(ex_style, class_name, L"", style, 100, 100, 100, 100,
wnd_, reinterpret_cast<HMENU>(id),
GetModuleHandle(NULL), NULL);
RTC_DCHECK(::IsWindow(*wnd) != FALSE);
@ -522,7 +522,7 @@ void MainWnd::LayoutConnectUI(bool show) {
static_cast<int>(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 {

View file

@ -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<char*>(src);
#endif
}
bool AudioDeviceWindowsCore::KeyPressed() const {

View file

@ -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();

View file

@ -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();
}

View file

@ -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();

View file

@ -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;

View file

@ -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();

View file

@ -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,10 +92,10 @@ 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,
result = EnumDisplaySettingsExW(device.DeviceName, ENUM_CURRENT_SETTINGS,
&device_mode, 0);
if (!result)
return DesktopRect();

View file

@ -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<DwmEnableCompositionFunc>(

View file

@ -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,11 +263,11 @@ 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,
CreateWindowExW(WS_EX_LAYERED, kMagnifierHostClass, kHostWindowName, 0, 0,
0, 0, 0, nullptr, nullptr, hInstance, nullptr);
if (!host_window_) {
mag_uninitialize_func_();
@ -278,7 +278,7 @@ bool ScreenCapturerWinMagnifier::InitializeMagnifier() {
}
// Create the magnifier control.
magnifier_window_ = CreateWindow(kMagnifierWindowClass, kMagnifierWindowName,
magnifier_window_ = CreateWindowW(kMagnifierWindowClass, kMagnifierWindowName,
WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
host_window_, nullptr, hInstance, nullptr);
if (!magnifier_window_) {

View file

@ -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<DwmIsCompositionEnabledFunc>(
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,

View file

@ -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.

View file

@ -62,32 +62,32 @@ std::string AddTrailingPathDelimiterIfNeeded(std::string directory) {
std::vector<std::string> 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<std::string> 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,
if (0 == ::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard,
&data))
return false;
return (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0;
@ -95,7 +95,7 @@ bool IsFile(const std::string& file) {
bool IsFolder(const std::string& file) {
WIN32_FILE_ATTRIBUTE_DATA data = {0};
if (0 == ::GetFileAttributesEx(ToUtf16(file).c_str(), GetFileExInfoStandard,
if (0 == ::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard,
&data))
return false;
return (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ==
@ -104,7 +104,7 @@ bool IsFolder(const std::string& file) {
absl::optional<size_t> GetFileSize(const std::string& file) {
WIN32_FILE_ATTRIBUTE_DATA data = {0};
if (::GetFileAttributesEx(ToUtf16(file).c_str(), GetFileExInfoStandard,
if (::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard,
&data) == 0)
return absl::nullopt;
return data.nFileSizeLow;

View file

@ -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.

View file

@ -44,21 +44,21 @@ 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,
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,
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,
return ::CreateFileW(ToUtf16(path).c_str(), GENERIC_READ | GENERIC_WRITE, 0,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
}

View file

@ -64,7 +64,7 @@ class RegKey {
RTC_DCHECK(rootkey && subkey && access && disposition);
HKEY subhkey = NULL;
LONG result =
::RegCreateKeyEx(rootkey, subkey, 0, NULL, REG_OPTION_NON_VOLATILE,
::RegCreateKeyExW(rootkey, subkey, 0, NULL, REG_OPTION_NON_VOLATILE,
access, NULL, &subhkey, disposition);
if (result == ERROR_SUCCESS) {
Close();
@ -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,7 +153,7 @@ class RegKey {
void* data,
DWORD* dsize,
DWORD* dtype) const {
LONG result = RegQueryValueEx(key_, name, 0, dtype,
LONG result = RegQueryValueExW(key_, name, 0, dtype,
reinterpret_cast<LPBYTE>(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<OSVERSIONINFO*>(&version_info));
::GetVersionExW(reinterpret_cast<OSVERSIONINFOW*>(&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<GetProductInfoPtr>(
::GetProcAddress(::GetModuleHandle(L"kernel32.dll"), "GetProductInfo"));
get_product_info = reinterpret_cast<GetProductInfoPtr>(::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<IsWow64ProcessFunc>(
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))

View file

@ -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

View file

@ -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.";
}

View file

@ -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_;

View file

@ -42,7 +42,7 @@ bool Win32Window::Create(HWND parent,
}
if (!window_class_) {
if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCWSTR>(&Win32Window::WndProc),
&instance_)) {
@ -51,20 +51,20 @@ bool Win32Window::Create(HWND parent,
}
// 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_);
}

View file

@ -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<std::vector<std::string>> 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<std::vector<std::string>>();
@ -154,7 +154,7 @@ absl::optional<std::vector<std::string>> 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)

View file

@ -99,7 +99,7 @@ absl::optional<std::string> 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));