This commit is contained in:
Jordan Woyak 2026-03-20 23:40:55 -05:00 committed by GitHub
commit c9360cfc8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 60 additions and 88 deletions

View File

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

View File

@ -123,7 +123,7 @@ static void ForEachNamedDevice(const std::function<bool(ComPtr<IMMDevice>, 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<IAudioClient> audio_client;

View File

@ -10,14 +10,6 @@
#include <chrono>
#include <cstdint>
#ifdef _WIN32
#include <tchar.h>
#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;

View File

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

View File

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

View File

@ -257,7 +257,7 @@ template <typename T>
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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<std::basic_string<TCHAR>>& guids)
static bool GetGUIDs(std::vector<std::wstring>& guids)
{
LONG status;
HKEY control_net_key;
@ -109,12 +109,12 @@ static bool GetGUIDs(std::vector<std::basic_string<TCHAR>>& 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<std::basic_string<TCHAR>>& 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<std::basic_string<TCHAR>>& guids)
return !guids.empty();
}
static bool OpenTAP(HANDLE& adapter, const std::basic_string<TCHAR>& 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<std::basic_string<TCHAR>> device_guids;
std::vector<std::wstring> device_guids;
if (!Win32TAPHelper::GetGUIDs(device_guids))
{

View File

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

View File

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

View File

@ -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<IPersistFile>();
if (!persist_file)
return false;

View File

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

View File

@ -334,21 +334,21 @@ void SetUserDirectory(std::string custom_path)
// Check our registry keys
wil::unique_hkey hkey;
DWORD local = 0;
std::unique_ptr<TCHAR[]> configPath;
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE,
std::unique_ptr<WCHAR[]> 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<LPBYTE>(&local), &size) != ERROR_SUCCESS)
{
local = 0;
}
size = 0;
RegQueryValueEx(hkey.get(), TEXT("UserConfigPath"), nullptr, nullptr, nullptr, &size);
configPath = std::make_unique<TCHAR[]>(size / sizeof(TCHAR));
if (RegQueryValueEx(hkey.get(), TEXT("UserConfigPath"), nullptr, nullptr,
RegQueryValueEx(hkey.get(), L"UserConfigPath", nullptr, nullptr, nullptr, &size);
configPath = std::make_unique<WCHAR[]>(size / sizeof(WCHAR));
if (RegQueryValueEx(hkey.get(), L"UserConfigPath", nullptr, nullptr,
reinterpret_cast<LPBYTE>(configPath.get()), &size) != ERROR_SUCCESS)
{
configPath.reset();
@ -365,7 +365,7 @@ void SetUserDirectory(std::string custom_path)
std::optional<std::string> 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<DWORD>((wstr_path.size() + 1) * sizeof(wchar_t)));
}
else // Case 6