1
0
mirror of synced 2025-01-19 01:24:15 +01:00

impr: Make Win32 API properly use unicode support

This commit is contained in:
WerWolv 2024-06-28 11:12:17 +02:00
parent b642c493d7
commit 91f6aae9ef
9 changed files with 26 additions and 25 deletions

View File

@ -59,6 +59,7 @@ macro(detectOS)
set(CMAKE_INSTALL_LIBDIR ".")
set(PLUGINS_INSTALL_LOCATION "plugins")
add_compile_definitions(WIN32_LEAN_AND_MEAN)
add_compile_definitions(UNICODE)
elseif (APPLE)
add_compile_definitions(OS_MACOS)
set(CMAKE_INSTALL_BINDIR ".")

View File

@ -443,7 +443,7 @@ namespace hex {
static auto setThreadDescription = reinterpret_cast<SetThreadDescriptionFunc>(
reinterpret_cast<uintptr_t>(
::GetProcAddress(
::GetModuleHandle("Kernel32.dll"),
::GetModuleHandleW(L"Kernel32.dll"),
"SetThreadDescription"
)
)

View File

@ -355,7 +355,7 @@ namespace hex {
url = "https://" + url;
#if defined(OS_WINDOWS)
ShellExecute(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
ShellExecuteA(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
#elif defined(OS_MACOS)
openWebpageMacos(url.c_str());
#elif defined(OS_LINUX)

View File

@ -16,7 +16,7 @@ namespace hex::messaging {
// Get the window name
auto length = ::GetWindowTextLength(hWnd);
std::string windowName(length + 1, '\x00');
::GetWindowText(hWnd, windowName.data(), windowName.size());
::GetWindowTextA(hWnd, windowName.data(), windowName.size());
// Check if the window is visible and if it's an ImHex window
if (::IsWindowVisible(hWnd) == TRUE && length != 0) {
@ -66,13 +66,13 @@ namespace hex::messaging {
bool setupNative() {
constexpr static auto UniqueMutexId = "ImHex/a477ea68-e334-4d07-a439-4f159c683763";
constexpr static auto UniqueMutexId = L"ImHex/a477ea68-e334-4d07-a439-4f159c683763";
// Check if an ImHex instance is already running by opening a global mutex
HANDLE globalMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, UniqueMutexId);
HANDLE globalMutex = OpenMutexW(MUTEX_ALL_ACCESS, FALSE, UniqueMutexId);
if (globalMutex == nullptr) {
// If no ImHex instance is running, create a new global mutex
globalMutex = CreateMutex(nullptr, FALSE, UniqueMutexId);
globalMutex = CreateMutexW(nullptr, FALSE, UniqueMutexId);
return true;
} else {
return false;

View File

@ -38,7 +38,7 @@ namespace hex {
void nativeErrorMessage(const std::string &message) {
log::fatal(message);
MessageBox(nullptr, message.c_str(), "Error", MB_ICONERROR | MB_OK);
MessageBoxA(nullptr, message.c_str(), "Error", MB_ICONERROR | MB_OK);
}
// Custom Window procedure for receiving OS events
@ -78,7 +78,7 @@ namespace hex {
// Handle Windows theme changes
if (lParam == 0) break;
if (LPCTSTR(lParam) == std::string_view("ImmersiveColorSet")) {
if (reinterpret_cast<const WCHAR*>(lParam) == std::wstring_view(L"ImmersiveColorSet")) {
EventOSThemeChanged::post();
}
@ -86,7 +86,7 @@ namespace hex {
}
case WM_SETCURSOR: {
if (LOWORD(lParam) != HTCLIENT) {
return CallWindowProc((WNDPROC)s_oldWndProc, hwnd, uMsg, wParam, lParam);
return CallWindowProc(reinterpret_cast<WNDPROC>(s_oldWndProc), hwnd, uMsg, wParam, lParam);
} else {
switch (ImGui::GetMouseCursor()) {
case ImGuiMouseCursor_Arrow:

View File

@ -381,8 +381,8 @@ namespace hex::plugin::builtin {
m_availableDrives.clear();
std::array<TCHAR, MAX_DEVICE_ID_LEN> deviceInstanceID = {};
std::array<TCHAR, 1024> description = {};
std::array<WCHAR, MAX_DEVICE_ID_LEN> deviceInstanceId = {};
std::array<WCHAR, 1024> description = {};
const GUID hddClass = GUID_DEVINTERFACE_DISK;
@ -404,7 +404,7 @@ namespace hex::plugin::builtin {
if (!SetupDiEnumInterfaceDevice(hDevInfo, nullptr, &hddClass, i, &interfaceData))
break;
if (CM_Get_Device_ID(deviceInfoData.DevInst, deviceInstanceID.data(), MAX_PATH, 0) != CR_SUCCESS)
if (CM_Get_Device_IDW(deviceInfoData.DevInst, deviceInstanceId.data(), MAX_PATH, 0) != CR_SUCCESS)
continue;
// Get the required size of the device path
@ -419,19 +419,19 @@ namespace hex::plugin::builtin {
if (!SetupDiGetDeviceInterfaceDetail(hDevInfo, &interfaceData, data, requiredSize, nullptr, nullptr))
continue;
auto path = data->DevicePath;
auto path = reinterpret_cast<const WCHAR*>(data->DevicePath);
// Query the friendly name of the device
DWORD size = 0;
DWORD propertyRegDataType = SPDRP_PHYSICAL_DEVICE_OBJECT_NAME;
SetupDiGetDeviceRegistryProperty(hDevInfo, &deviceInfoData, SPDRP_FRIENDLYNAME,
SetupDiGetDeviceRegistryPropertyW(hDevInfo, &deviceInfoData, SPDRP_FRIENDLYNAME,
&propertyRegDataType, reinterpret_cast<BYTE*>(description.data()),
sizeof(description),
&size);
auto friendlyName = description.data();
m_availableDrives.insert({ path, friendlyName });
m_availableDrives.insert({ utf16ToUtf8(path), utf16ToUtf8(friendlyName) });
}
// Add all logical drives

View File

@ -17,9 +17,9 @@ namespace hex::plugin::windows {
void drawContent() override;
private:
std::vector<std::pair<std::string, std::string>> m_comPorts;
std::vector<std::pair<std::wstring, std::wstring>> m_comPorts;
std::vector<std::pair<std::string, std::string>> getAvailablePorts() const;
std::vector<std::pair<std::wstring, std::wstring>> getAvailablePorts() const;
bool connect();
bool disconnect();

View File

@ -28,11 +28,11 @@ static void detectSystemTheme() {
return;
HKEY hkey;
if (RegOpenKey(HKEY_CURRENT_USER, R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", &hkey) == ERROR_SUCCESS) {
if (RegOpenKeyW(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", &hkey) == ERROR_SUCCESS) {
DWORD value = 0;
DWORD size = sizeof(DWORD);
auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
auto error = RegQueryValueExW(hkey, L"AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
if (error == ERROR_SUCCESS) {
RequestChangeTheme::post(value == 0 ? "Dark" : "Light");
}

View File

@ -169,14 +169,14 @@ namespace hex::plugin::windows {
}
}
std::vector<std::pair<std::string, std::string>> ViewTTYConsole::getAvailablePorts() const {
std::vector<std::pair<std::string, std::string>> result;
std::vector<char> buffer(0xFFF, 0x00);
std::vector<std::pair<std::wstring, std::wstring>> ViewTTYConsole::getAvailablePorts() const {
std::vector<std::pair<std::wstring, std::wstring>> result;
std::vector<wchar_t> buffer(0xFFF, 0x00);
for (u16 portNumber = 0; portNumber <= 255; portNumber++) {
std::string port = "COM" + std::to_string(portNumber);
std::wstring port = L"COM" + std::to_wstring(portNumber);
if (::QueryDosDevice(port.c_str(), buffer.data(), buffer.size()) != 0) {
if (::QueryDosDeviceW(port.c_str(), buffer.data(), buffer.size()) != 0) {
result.emplace_back(port, buffer.data());
}
}
@ -189,7 +189,7 @@ namespace hex::plugin::windows {
ui::ToastError::open("hex.windows.view.tty_console.no_available_port"_lang);
return true; // If false, connect_error error popup will override this error popup
}
m_portHandle = ::CreateFile((R"(\\.\)" + m_comPorts[m_selectedPort].first).c_str(),
m_portHandle = ::CreateFileW((LR"(\\.\)" + m_comPorts[m_selectedPort].first).c_str(),
GENERIC_READ | GENERIC_WRITE,
0,
nullptr,