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) <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,7 @@ coreaudio-rs = { version = "0.11", optional = true }
|
|||||||
windows = { version = "0.58", optional = true, features = [
|
windows = { version = "0.58", optional = true, features = [
|
||||||
"Win32_Foundation",
|
"Win32_Foundation",
|
||||||
"Win32_Media_Audio",
|
"Win32_Media_Audio",
|
||||||
|
"Win32_Security",
|
||||||
"Win32_System_Com",
|
"Win32_System_Com",
|
||||||
"Win32_System_Com_StructuredStorage",
|
"Win32_System_Com_StructuredStorage",
|
||||||
"Win32_System_Threading",
|
"Win32_System_Threading",
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use std::sync::Arc;
|
|||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
use windows::core::{Interface, GUID};
|
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::{
|
use windows::Win32::Media::Audio::{
|
||||||
eCapture, eCommunications, AudioCategory_Communications, AudioClientProperties,
|
eCapture, eCommunications, AudioCategory_Communications, AudioClientProperties,
|
||||||
IAudioCaptureClient, IAudioClient, IAudioClient2, IMMDeviceEnumerator, MMDeviceEnumerator,
|
IAudioCaptureClient, IAudioClient, IAudioClient2, IMMDeviceEnumerator, MMDeviceEnumerator,
|
||||||
@@ -320,9 +320,13 @@ unsafe fn capture_thread_main(
|
|||||||
/// PKEY_Device_FriendlyName requires IPropertyStore + PROPVARIANT plumbing
|
/// PKEY_Device_FriendlyName requires IPropertyStore + PROPVARIANT plumbing
|
||||||
/// that's far more ceremony than a log line justifies; the ID is already
|
/// that's far more ceremony than a log line justifies; the ID is already
|
||||||
/// sufficient to confirm we opened the right endpoint.
|
/// 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(
|
unsafe fn device_name(
|
||||||
device: &windows::Win32::Media::Audio::IMMDevice,
|
device: &windows::Win32::Media::Audio::IMMDevice,
|
||||||
) -> Result<String, anyhow::Error> {
|
) -> Result<String, anyhow::Error> {
|
||||||
let id = device.GetId().context("IMMDevice::GetId failed")?;
|
let id = unsafe { device.GetId() }.context("IMMDevice::GetId failed")?;
|
||||||
Ok(id.to_string().unwrap_or_else(|_| "<non-utf16>".to_string()))
|
Ok(unsafe { id.to_string() }.unwrap_or_else(|_| "<non-utf16>".to_string()))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user