From 45027812987543351fcf189f9430d5ed6a583753 Mon Sep 17 00:00:00 2001 From: Ame <104745335+ameknite@users.noreply.github.com> Date: Sat, 2 Mar 2024 17:33:25 -0600 Subject: [PATCH] windows 0.52 -> 0.54 (#855) --- Cargo.toml | 2 +- src/host/wasapi/com.rs | 23 +++++++++++------------ src/host/wasapi/device.rs | 6 +++--- src/host/wasapi/stream.rs | 7 ++----- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 548693f..3e00f11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ clap = { version = "4.0", features = ["derive"] } ndk-glue = "0.7" [target.'cfg(target_os = "windows")'.dependencies] -windows = { version = "0.52.0", features = [ +windows = { version = "0.54.0", features = [ "Win32_Media_Audio", "Win32_Foundation", "Win32_Devices_Properties", diff --git a/src/host/wasapi/com.rs b/src/host/wasapi/com.rs index 0fe2dec..710f333 100644 --- a/src/host/wasapi/com.rs +++ b/src/host/wasapi/com.rs @@ -15,18 +15,17 @@ thread_local!(static COM_INITIALIZED: ComInitialized = { // That's OK though since COM ensures thread-safety/compatibility through marshalling when // necessary. let result = CoInitializeEx(None, COINIT_APARTMENTTHREADED); - match result.clone().map_err(|e| e.code()) { - Ok(_) | - Err(RPC_E_CHANGED_MODE) => { - ComInitialized { - result, - _ptr: PhantomData, - } - }, - Err(e) => { - // COM initialization failed in another way, something is really wrong. - panic!("Failed to initialize COM: {}", IoError::from_raw_os_error(e.0)); + if result.is_ok() || result == RPC_E_CHANGED_MODE { + ComInitialized { + result, + _ptr: PhantomData, } + } else { + // COM initialization failed in another way, something is really wrong. + panic!( + "Failed to initialize COM: {}", + IoError::from_raw_os_error(result.0) + ); } } }); @@ -36,7 +35,7 @@ thread_local!(static COM_INITIALIZED: ComInitialized = { // We store a raw pointer because it's the only way at the moment to remove `Send`/`Sync` from the // object. struct ComInitialized { - result: windows::core::Result<()>, + result: windows::core::HRESULT, _ptr: PhantomData<*mut ()>, } diff --git a/src/host/wasapi/device.rs b/src/host/wasapi/device.rs index 1ab9b64..983c8c5 100644 --- a/src/host/wasapi/device.rs +++ b/src/host/wasapi/device.rs @@ -17,7 +17,7 @@ use std::time::Duration; use super::com; use super::{windows_err_to_cpal_err, windows_err_to_cpal_err_message}; -use windows::core::ComInterface; +use windows::core::Interface; use windows::core::GUID; use windows::Win32::Devices::Properties; use windows::Win32::Foundation; @@ -297,10 +297,10 @@ impl Device { DeviceNameError::from(err) })?; - let prop_variant = &property_value.Anonymous.Anonymous; + let prop_variant = &property_value.as_raw().Anonymous.Anonymous; // Read the friendly-name from the union data field, expecting a *const u16. - if prop_variant.vt != VT_LPWSTR { + if prop_variant.vt != VT_LPWSTR.0 { let description = format!( "property store produced invalid data: {:?}", prop_variant.vt diff --git a/src/host/wasapi/stream.rs b/src/host/wasapi/stream.rs index 57332a1..72c7836 100644 --- a/src/host/wasapi/stream.rs +++ b/src/host/wasapi/stream.rs @@ -243,11 +243,8 @@ fn wait_for_handle_signal(handles: &[Foundation::HANDLE]) -> Result windows::core::Error::OK, - Err(err) => err, - }; - let description = format!("`WaitForMultipleObjectsEx failed: {}", err); + let err = unsafe { Foundation::GetLastError() }; + let description = format!("`WaitForMultipleObjectsEx failed: {:?}", err); let err = BackendSpecificError { description }; return Err(err); }