diff --git a/Source/Core/AudioCommon/OpenALStream.cpp b/Source/Core/AudioCommon/OpenALStream.cpp index a059d428c0..e4f62cf440 100644 --- a/Source/Core/AudioCommon/OpenALStream.cpp +++ b/Source/Core/AudioCommon/OpenALStream.cpp @@ -70,7 +70,7 @@ static bool InitLibrary() if (s_openal_dll) return true; - s_openal_dll = ::LoadLibrary(TEXT("openal32.dll")); + s_openal_dll = ::LoadLibrary(L"openal32.dll"); if (!s_openal_dll) return false; diff --git a/Source/Core/AudioCommon/WASAPIStream.cpp b/Source/Core/AudioCommon/WASAPIStream.cpp index afd5531ae8..ab9fcc8bb4 100644 --- a/Source/Core/AudioCommon/WASAPIStream.cpp +++ b/Source/Core/AudioCommon/WASAPIStream.cpp @@ -123,7 +123,7 @@ static void ForEachNamedDevice(const std::function, std:: wil::unique_prop_variant device_name; device_properties->GetValue(PKEY_Device_FriendlyName, device_name.addressof()); - if (!callback(std::move(device), TStrToUTF8(device_name.pwszVal))) + if (!callback(std::move(device), WStringToUTF8(device_name.pwszVal))) break; } } @@ -207,7 +207,7 @@ bool WASAPIStream::SetRunning(bool running) wil::unique_prop_variant device_name; device_properties->GetValue(PKEY_Device_FriendlyName, device_name.addressof()); - INFO_LOG_FMT(AUDIO, "Using audio endpoint '{}'", TStrToUTF8(device_name.pwszVal)); + INFO_LOG_FMT(AUDIO, "Using audio endpoint '{}'", WStringToUTF8(device_name.pwszVal)); ComPtr audio_client; diff --git a/Source/Core/Common/CommonTypes.h b/Source/Core/Common/CommonTypes.h index 68397c1c3f..012d44406a 100644 --- a/Source/Core/Common/CommonTypes.h +++ b/Source/Core/Common/CommonTypes.h @@ -10,14 +10,6 @@ #include #include -#ifdef _WIN32 -#include -#else -// For using Windows lock code -#define TCHAR char -#define LONG int -#endif - using u8 = std::uint8_t; using u16 = std::uint16_t; using u32 = std::uint32_t; diff --git a/Source/Core/Common/DirectIOFile.cpp b/Source/Core/Common/DirectIOFile.cpp index bfe598dc48..caeab05cde 100644 --- a/Source/Core/Common/DirectIOFile.cpp +++ b/Source/Core/Common/DirectIOFile.cpp @@ -103,7 +103,7 @@ bool DirectIOFile::Open(const std::string& path, AccessMode access_mode, OpenMod else if (open_mode == OpenMode::Existing) creation_disposition = OPEN_EXISTING; - m_handle = CreateFile(UTF8ToTStr(path).c_str(), desired_access, share_mode, nullptr, + m_handle = CreateFile(UTF8ToWString(path).c_str(), desired_access, share_mode, nullptr, creation_disposition, FILE_ATTRIBUTE_NORMAL, nullptr); if (!IsOpen()) WARN_LOG_FMT(COMMON, "CreateFile: {}", Common::GetLastErrorString()); diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 1dbbb4ac41..de8a53bad2 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -634,7 +634,7 @@ bool SetCurrentDir(const std::string& directory) std::string CreateTempDir() { #ifdef _WIN32 - TCHAR temp[MAX_PATH]; + WCHAR temp[MAX_PATH]; if (!GetTempPath(MAX_PATH, temp)) return ""; @@ -648,7 +648,7 @@ std::string CreateTempDir() { return ""; } - std::string dir = TStrToUTF8(temp) + "/" + TStrToUTF8(tguid); + std::string dir = WStringToUTF8(temp) + "/" + WStringToUTF8(tguid); if (!CreateDir(dir)) return ""; dir = ReplaceAll(dir, "\\", DIR_SEP); diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index cfe6eddffb..234c433eb4 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -257,7 +257,7 @@ template void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmode openmode) { #ifdef _WIN32 - fstream.open(UTF8ToTStr(filename).c_str(), openmode); + fstream.open(UTF8ToWString(filename).c_str(), openmode); #else #ifdef ANDROID // Unfortunately it seems like the non-standard __open is the only way to use a file descriptor diff --git a/Source/Core/Common/GL/GLInterface/WGL.cpp b/Source/Core/Common/GL/GLInterface/WGL.cpp index a85a27a79d..3735e9a636 100644 --- a/Source/Core/Common/GL/GLInterface/WGL.cpp +++ b/Source/Core/Common/GL/GLInterface/WGL.cpp @@ -219,7 +219,7 @@ void* GLContextWGL::GetFuncAddress(const std::string& name) { // Using GetModuleHandle here is okay, since we import functions from opengl32.dll, it's // guaranteed to be loaded. - HMODULE opengl_module = GetModuleHandle(TEXT("opengl32.dll")); + HMODULE opengl_module = GetModuleHandle(L"opengl32.dll"); func = GetProcAddress(opengl_module, name.c_str()); } diff --git a/Source/Core/Common/IOFile.cpp b/Source/Core/Common/IOFile.cpp index 9402da1a94..bd4321e275 100644 --- a/Source/Core/Common/IOFile.cpp +++ b/Source/Core/Common/IOFile.cpp @@ -70,11 +70,12 @@ bool IOFile::Open(const std::string& filename, const char openmode[], #ifdef _WIN32 if (sh == SharedAccess::Default) { - m_good = _tfopen_s(&m_file, UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str()) == 0; + m_good = + _wfopen_s(&m_file, UTF8ToWString(filename).c_str(), UTF8ToWString(openmode).c_str()) == 0; } else if (sh == SharedAccess::Read) { - m_file = _tfsopen(UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str(), SH_DENYWR); + m_file = _wfsopen(UTF8ToWString(filename).c_str(), UTF8ToWString(openmode).c_str(), SH_DENYWR); m_good = m_file != nullptr; } #else diff --git a/Source/Core/Common/MemArenaWin.cpp b/Source/Core/Common/MemArenaWin.cpp index 4c296da631..6b30ed05c1 100644 --- a/Source/Core/Common/MemArenaWin.cpp +++ b/Source/Core/Common/MemArenaWin.cpp @@ -123,7 +123,7 @@ void MemArena::GrabSHMSegment(size_t size, std::string_view base_name) const std::string name = fmt::format("{}.{}", base_name, GetCurrentProcessId()); m_memory_handle = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, GetHighDWORD(size), - GetLowDWORD(size), UTF8ToTStr(name).c_str()); + GetLowDWORD(size), UTF8ToWString(name).c_str()); } void MemArena::ReleaseSHMSegment() diff --git a/Source/Core/Common/MsgHandler.cpp b/Source/Core/Common/MsgHandler.cpp index f6201c651f..8ac039c5cd 100644 --- a/Source/Core/Common/MsgHandler.cpp +++ b/Source/Core/Common/MsgHandler.cpp @@ -31,7 +31,7 @@ bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, MsgTy if (style == MsgType::Warning) window_style = MB_ICONWARNING; - return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(), + return IDYES == MessageBox(0, UTF8ToWString(text).c_str(), UTF8ToWString(caption).c_str(), window_style | (yes_no ? MB_YESNO : MB_OK)); #else fmt::print(stderr, "{}\n", text); diff --git a/Source/Core/Common/StringUtil.h b/Source/Core/Common/StringUtil.h index 0cc4e6c15e..90cd28c9cf 100644 --- a/Source/Core/Common/StringUtil.h +++ b/Source/Core/Common/StringUtil.h @@ -243,28 +243,6 @@ std::u16string UTF8ToUTF16(std::string_view input); std::wstring UTF8ToWString(std::string_view str); -#ifdef _UNICODE -inline std::string TStrToUTF8(std::wstring_view str) -{ - return WStringToUTF8(str); -} - -inline std::wstring UTF8ToTStr(std::string_view str) -{ - return UTF8ToWString(str); -} -#else -inline std::string TStrToUTF8(std::string_view str) -{ - return str; -} - -inline std::string UTF8ToTStr(std::string_view str) -{ - return str; -} -#endif - #endif std::filesystem::path StringToPath(std::string_view path); diff --git a/Source/Core/Common/WindowsRegistry.cpp b/Source/Core/Common/WindowsRegistry.cpp index 6067420669..896de81b23 100644 --- a/Source/Core/Common/WindowsRegistry.cpp +++ b/Source/Core/Common/WindowsRegistry.cpp @@ -66,7 +66,7 @@ OSVERSIONINFOW GetOSVersion() // Fallback to version from PEB typedef DWORD(WINAPI * RtlGetVersion_t)(PRTL_OSVERSIONINFOW); auto RtlGetVersion = - (RtlGetVersion_t)GetProcAddress(GetModuleHandle(TEXT("ntdll")), "RtlGetVersion"); + (RtlGetVersion_t)GetProcAddress(GetModuleHandle(L"ntdll"), "RtlGetVersion"); RtlGetVersion(&info); // Clear fields which would not be filled in by registry query info.dwPlatformId = 0; diff --git a/Source/Core/Core/HW/EXI/BBA/TAP_Win32.cpp b/Source/Core/Core/HW/EXI/BBA/TAP_Win32.cpp index c0abd75e43..8e52b6bb6c 100644 --- a/Source/Core/Core/HW/EXI/BBA/TAP_Win32.cpp +++ b/Source/Core/Core/HW/EXI/BBA/TAP_Win32.cpp @@ -12,7 +12,7 @@ namespace Win32TAPHelper { -static bool IsTAPDevice(const TCHAR* guid) +static bool IsTAPDevice(const WCHAR* guid) { HKEY netcard_key; LONG status; @@ -26,13 +26,13 @@ static bool IsTAPDevice(const TCHAR* guid) while (true) { - TCHAR enum_name[256]; - TCHAR unit_string[256]; + WCHAR enum_name[256]; + WCHAR unit_string[256]; HKEY unit_key; - TCHAR component_id_string[] = _T("ComponentId"); - TCHAR component_id[256]; - TCHAR net_cfg_instance_id_string[] = _T("NetCfgInstanceId"); - TCHAR net_cfg_instance_id[256]; + WCHAR component_id_string[] = L"ComponentId"; + WCHAR component_id[256]; + WCHAR net_cfg_instance_id_string[] = L"NetCfgInstanceId"; + WCHAR net_cfg_instance_id[256]; DWORD data_type; len = _countof(enum_name); @@ -43,8 +43,8 @@ static bool IsTAPDevice(const TCHAR* guid) else if (status != ERROR_SUCCESS) return false; - _sntprintf(unit_string, _countof(unit_string), _T("%s\\%s"), ADAPTER_KEY, enum_name); - unit_string[_countof(unit_string) - 1] = _T('\0'); + _snwprintf(unit_string, _countof(unit_string), L"%s\\%s", ADAPTER_KEY, enum_name); + unit_string[_countof(unit_string) - 1] = L'\0'; status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit_string, 0, KEY_READ, &unit_key); @@ -66,11 +66,11 @@ static bool IsTAPDevice(const TCHAR* guid) if (status == ERROR_SUCCESS && data_type == REG_SZ) { - TCHAR* const component_id_sub = _tcsstr(component_id, TAP_COMPONENT_ID); + WCHAR* const component_id_sub = wcsstr(component_id, TAP_COMPONENT_ID); if (component_id_sub) { - if (!_tcscmp(component_id_sub, TAP_COMPONENT_ID) && !_tcscmp(net_cfg_instance_id, guid)) + if (!wcscmp(component_id_sub, TAP_COMPONENT_ID) && !wcscmp(net_cfg_instance_id, guid)) { RegCloseKey(unit_key); RegCloseKey(netcard_key); @@ -88,7 +88,7 @@ static bool IsTAPDevice(const TCHAR* guid) return false; } -static bool GetGUIDs(std::vector>& guids) +static bool GetGUIDs(std::vector& guids) { LONG status; HKEY control_net_key; @@ -109,12 +109,12 @@ static bool GetGUIDs(std::vector>& guids) for (DWORD i = 0; i < cSubKeys; i++) { - TCHAR enum_name[256]; - TCHAR connection_string[256]; + WCHAR enum_name[256]; + WCHAR connection_string[256]; HKEY connection_key; - TCHAR name_data[256]; + WCHAR name_data[256]; DWORD name_type; - const TCHAR name_string[] = _T("Name"); + const WCHAR name_string[] = L"Name"; len = _countof(enum_name); status = RegEnumKeyEx(control_net_key, i, enum_name, &len, nullptr, nullptr, nullptr, nullptr); @@ -122,9 +122,9 @@ static bool GetGUIDs(std::vector>& guids) if (status != ERROR_SUCCESS) continue; - _sntprintf(connection_string, _countof(connection_string), _T("%s\\%s\\Connection"), + _snwprintf(connection_string, _countof(connection_string), L"%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, enum_name); - connection_string[_countof(connection_string) - 1] = _T('\0'); + connection_string[_countof(connection_string) - 1] = L'\0'; status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, connection_string, 0, KEY_READ, &connection_key); @@ -155,7 +155,7 @@ static bool GetGUIDs(std::vector>& guids) return !guids.empty(); } -static bool OpenTAP(HANDLE& adapter, const std::basic_string& device_guid) +static bool OpenTAP(HANDLE& adapter, const std::wstring& device_guid) { auto const device_path = USERMODEDEVICEDIR + device_guid + TAPSUFFIX; @@ -180,7 +180,7 @@ bool CEXIETHERNET::TAPNetworkInterface::Activate() return true; DWORD len; - std::vector> device_guids; + std::vector device_guids; if (!Win32TAPHelper::GetGUIDs(device_guids)) { diff --git a/Source/Core/Core/HW/EXI/BBA/TAP_Win32.h b/Source/Core/Core/HW/EXI/BBA/TAP_Win32.h index ec62f7a1e9..05c57e0bb4 100644 --- a/Source/Core/Core/HW/EXI/BBA/TAP_Win32.h +++ b/Source/Core/Core/HW/EXI/BBA/TAP_Win32.h @@ -68,19 +68,19 @@ constexpr int TAP_WIN32_MIN_MINOR = 0; //================= #define ADAPTER_KEY \ - _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}") + L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}" #define NETWORK_CONNECTIONS_KEY \ - _T("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}") + L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}" //====================== // Filesystem prefixes //====================== -#define USERMODEDEVICEDIR _T("\\\\.\\Global\\") -#define SYSDEVICEDIR _T("\\Device\\") -#define USERDEVICEDIR _T("\\DosDevices\\Global\\") -#define TAPSUFFIX _T(".tap") +#define USERMODEDEVICEDIR L"\\\\.\\Global\\" +#define SYSDEVICEDIR L"\\Device\\" +#define USERDEVICEDIR L"\\DosDevices\\Global\\" +#define TAPSUFFIX L".tap" //========================================================= // TAP_COMPONENT_ID -- This string defines the TAP driver @@ -88,4 +88,4 @@ constexpr int TAP_WIN32_MIN_MINOR = 0; // simultaneously. //========================================================= -#define TAP_COMPONENT_ID _T("tap0901") +#define TAP_COMPONENT_ID L"tap0901" diff --git a/Source/Core/DolphinNoGUI/PlatformWin32.cpp b/Source/Core/DolphinNoGUI/PlatformWin32.cpp index 7304332682..5825ce06e4 100644 --- a/Source/Core/DolphinNoGUI/PlatformWin32.cpp +++ b/Source/Core/DolphinNoGUI/PlatformWin32.cpp @@ -29,7 +29,7 @@ public: WindowSystemInfo GetWindowSystemInfo() const override; private: - static constexpr TCHAR WINDOW_CLASS_NAME[] = _T("DolphinNoGUI"); + static constexpr WCHAR WINDOW_CLASS_NAME[] = L"DolphinNoGUI"; static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); @@ -70,7 +70,7 @@ bool PlatformWin32::RegisterRenderWindowClass() if (!RegisterClassEx(&wc)) { - MessageBox(nullptr, _T("Window registration failed."), _T("Error"), MB_ICONERROR | MB_OK); + MessageBox(nullptr, L"Window registration failed.", L"Error", MB_ICONERROR | MB_OK); return false; } @@ -79,13 +79,13 @@ bool PlatformWin32::RegisterRenderWindowClass() bool PlatformWin32::CreateRenderWindow() { - m_hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WINDOW_CLASS_NAME, _T("Dolphin"), WS_OVERLAPPEDWINDOW, + m_hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WINDOW_CLASS_NAME, L"Dolphin", WS_OVERLAPPEDWINDOW, m_window_x < 0 ? CW_USEDEFAULT : m_window_x, m_window_y < 0 ? CW_USEDEFAULT : m_window_y, m_window_width, m_window_height, nullptr, nullptr, GetModuleHandle(nullptr), this); if (!m_hwnd) { - MessageBox(nullptr, _T("CreateWindowEx failed."), _T("Error"), MB_ICONERROR | MB_OK); + MessageBox(nullptr, L"CreateWindowEx failed.", L"Error", MB_ICONERROR | MB_OK); return false; } diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index c63230aa55..055740ba0b 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -823,7 +823,7 @@ bool GameList::AddShortcutToDesktop() const auto game = GetSelectedGame(); const auto& file_path = game->GetFilePath(); - std::wstring args = UTF8ToTStr("-e \"" + file_path + "\""); + std::wstring args = UTF8ToWString("-e \"" + file_path + "\""); if (FAILED(shell_link->SetArguments(args.c_str()))) return false; @@ -838,7 +838,8 @@ bool GameList::AddShortcutToDesktop() return Common::Contains(illegal_characters, ch); }); - std::wstring desktop_path = std::wstring(desktop.get()) + UTF8ToTStr("\\" + game_name + ".lnk"); + std::wstring desktop_path = + std::wstring(desktop.get()) + UTF8ToWString("\\" + game_name + ".lnk"); auto persist_file = shell_link.try_query(); if (!persist_file) return false; diff --git a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp index ebe79f8984..73f10c0e02 100644 --- a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp +++ b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp @@ -146,7 +146,7 @@ void Init() if (!hXInput) { // Drop back to DXSDK June 2010 version. Requires DX June 2010 redist. - hXInput = ::LoadLibrary(TEXT("xinput1_3.dll")); + hXInput = ::LoadLibrary(L"xinput1_3.dll"); if (!hXInput) { return; diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index c56d1e1d09..e335f6e17f 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -334,21 +334,21 @@ void SetUserDirectory(std::string custom_path) // Check our registry keys wil::unique_hkey hkey; DWORD local = 0; - std::unique_ptr configPath; - if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE, + std::unique_ptr configPath; + if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Dolphin Emulator", 0, KEY_QUERY_VALUE, hkey.put()) == ERROR_SUCCESS) { DWORD size = sizeof(local); - if (RegQueryValueEx(hkey.get(), TEXT("LocalUserConfig"), nullptr, nullptr, + if (RegQueryValueEx(hkey.get(), L"LocalUserConfig", nullptr, nullptr, reinterpret_cast(&local), &size) != ERROR_SUCCESS) { local = 0; } size = 0; - RegQueryValueEx(hkey.get(), TEXT("UserConfigPath"), nullptr, nullptr, nullptr, &size); - configPath = std::make_unique(size / sizeof(TCHAR)); - if (RegQueryValueEx(hkey.get(), TEXT("UserConfigPath"), nullptr, nullptr, + RegQueryValueEx(hkey.get(), L"UserConfigPath", nullptr, nullptr, nullptr, &size); + configPath = std::make_unique(size / sizeof(WCHAR)); + if (RegQueryValueEx(hkey.get(), L"UserConfigPath", nullptr, nullptr, reinterpret_cast(configPath.get()), &size) != ERROR_SUCCESS) { configPath.reset(); @@ -365,7 +365,7 @@ void SetUserDirectory(std::string custom_path) std::optional old_user_folder; if (documents_found) { - old_user_folder = TStrToUTF8(documents.get()) + DIR_SEP NORMAL_USER_DIR DIR_SEP; + old_user_folder = WStringToUTF8(documents.get()) + DIR_SEP NORMAL_USER_DIR DIR_SEP; } if (local) // Case 1-2 @@ -374,7 +374,7 @@ void SetUserDirectory(std::string custom_path) } else if (configPath) // Case 3 { - user_path = TStrToUTF8(configPath.get()); + user_path = WStringToUTF8(configPath.get()); } else if (old_user_folder && File::Exists(old_user_folder.value())) // Case 4 { @@ -382,15 +382,15 @@ void SetUserDirectory(std::string custom_path) } else if (appdata_found) // Case 5 { - user_path = TStrToUTF8(appdata.get()) + DIR_SEP NORMAL_USER_DIR DIR_SEP; + user_path = WStringToUTF8(appdata.get()) + DIR_SEP NORMAL_USER_DIR DIR_SEP; // Set the UserConfigPath value in the registry for backwards compatibility with older Dolphin // builds, which will look for the default User directory in Documents. If we set this key, // they will use this as the User directory instead. // (If we're in this case, then this key doesn't exist, so it's OK to set it.) std::wstring wstr_path = UTF8ToWString(user_path); - RegSetKeyValueW(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), TEXT("UserConfigPath"), - REG_SZ, wstr_path.c_str(), + RegSetKeyValueW(HKEY_CURRENT_USER, L"Software\\Dolphin Emulator", L"UserConfigPath", REG_SZ, + wstr_path.c_str(), static_cast((wstr_path.size() + 1) * sizeof(wchar_t))); } else // Case 6