From 4e9244eb00e1d6da10c9924459f020096c377d0e Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Fri, 10 Apr 2026 14:36:50 +0400 Subject: [PATCH] fix(windows): add Win32_Security feature + 2024 edition unsafe wrappers - CreateEventW is gated behind Win32_Security in the windows crate because its signature takes SECURITY_ATTRIBUTES; add to features. - Remove unused HANDLE import. - Wrap GetId() and PWSTR::to_string() in explicit unsafe { ... } blocks for Rust 2024 edition's unsafe_op_in_unsafe_fn lint. Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/wzp-client/Cargo.toml | 1 + crates/wzp-client/src/audio_wasapi.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/wzp-client/Cargo.toml b/crates/wzp-client/Cargo.toml index 6160a74..3d11f0f 100644 --- a/crates/wzp-client/Cargo.toml +++ b/crates/wzp-client/Cargo.toml @@ -40,6 +40,7 @@ coreaudio-rs = { version = "0.11", optional = true } windows = { version = "0.58", optional = true, features = [ "Win32_Foundation", "Win32_Media_Audio", + "Win32_Security", "Win32_System_Com", "Win32_System_Com_StructuredStorage", "Win32_System_Threading", diff --git a/crates/wzp-client/src/audio_wasapi.rs b/crates/wzp-client/src/audio_wasapi.rs index e98dfa7..b3612eb 100644 --- a/crates/wzp-client/src/audio_wasapi.rs +++ b/crates/wzp-client/src/audio_wasapi.rs @@ -21,7 +21,7 @@ use std::sync::Arc; use anyhow::{anyhow, Context}; use tracing::{info, warn}; use windows::core::{Interface, GUID}; -use windows::Win32::Foundation::{CloseHandle, BOOL, HANDLE, WAIT_OBJECT_0}; +use windows::Win32::Foundation::{CloseHandle, BOOL, WAIT_OBJECT_0}; use windows::Win32::Media::Audio::{ eCapture, eCommunications, AudioCategory_Communications, AudioClientProperties, IAudioCaptureClient, IAudioClient, IAudioClient2, IMMDeviceEnumerator, MMDeviceEnumerator, @@ -320,9 +320,13 @@ unsafe fn capture_thread_main( /// PKEY_Device_FriendlyName requires IPropertyStore + PROPVARIANT plumbing /// that's far more ceremony than a log line justifies; the ID is already /// sufficient to confirm we opened the right endpoint. +/// +/// Rust 2024 edition's `unsafe_op_in_unsafe_fn` lint requires explicit +/// `unsafe { ... }` blocks inside `unsafe fn` bodies for each unsafe call, +/// even though the whole function is already marked unsafe. unsafe fn device_name( device: &windows::Win32::Media::Audio::IMMDevice, ) -> Result { - let id = device.GetId().context("IMMDevice::GetId failed")?; - Ok(id.to_string().unwrap_or_else(|_| "".to_string())) + let id = unsafe { device.GetId() }.context("IMMDevice::GetId failed")?; + Ok(unsafe { id.to_string() }.unwrap_or_else(|_| "".to_string())) }