From 1ebbba10bb7e0f6c6efb52aa58b6c9f7acd4ac90 Mon Sep 17 00:00:00 2001 From: jodnr Date: Sat, 21 Feb 2026 10:19:18 +0900 Subject: [PATCH] fix: Windows build errors with windows crate v0.52 - Replace GetWindowText with GetWindowTextW (Unicode version) - Fix HWND type import in platform.rs - Fix enum_window_callback signature to use LPARAM and BOOL types - Fix EnumWindows call to use LPARAM() wrapper Fixes #8 --- src/tools/window.rs | 2 +- src/utils/platform.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tools/window.rs b/src/tools/window.rs index 556a830..9ac8848 100644 --- a/src/tools/window.rs +++ b/src/tools/window.rs @@ -19,7 +19,7 @@ use objc::{msg_send, sel, sel_impl}; #[cfg(target_os = "windows")] use windows::Win32::Foundation::{HWND, RECT}; #[cfg(target_os = "windows")] -use windows::Win32::UI::WindowsAndMessaging::{GetWindowRect, GetWindowText, GetWindowTextLengthW}; +use windows::Win32::UI::WindowsAndMessaging::{GetWindowRect, GetWindowTextW, GetWindowTextLengthW}; #[cfg(target_os = "linux")] use x11::xlib; diff --git a/src/utils/platform.rs b/src/utils/platform.rs index a2b1d78..1ddb34d 100644 --- a/src/utils/platform.rs +++ b/src/utils/platform.rs @@ -13,7 +13,7 @@ struct EnumData { #[cfg(target_os = "windows")] pub fn get_window_by_pid(pid: u32) -> Result> { - use windows::Win32::Foundation::HWND; + use windows::Win32::Foundation::LPARAM; use windows::Win32::UI::WindowsAndMessaging::EnumWindows; use std::sync::Mutex; @@ -25,8 +25,8 @@ pub fn get_window_by_pid(pid: u32) -> Result Result i32 { +unsafe extern "system" fn enum_window_callback(hwnd: windows::Win32::Foundation::HWND, lparam: windows::Win32::Foundation::LPARAM) -> windows::Win32::Foundation::BOOL { use std::sync::Mutex; use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId; - let data = &*(lparam as *const Mutex); + let data = &*(lparam.0 as *const Mutex); let mut process_id = 0u32; GetWindowThreadProcessId(hwnd, Some(&mut process_id)); let mut enum_data = data.lock().unwrap(); if process_id == enum_data.target_pid { enum_data.window = Some(hwnd); - return 0; + return windows::Win32::Foundation::BOOL(0); } - 1 + windows::Win32::Foundation::BOOL(1) } #[cfg(target_os = "linux")]