diff --git a/Cargo.toml b/Cargo.toml index b221c6a..7b98487 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wmi" -version = "0.13.1" +version = "0.13.2" authors = ["Ohad Ravid "] edition = "2021" license = "MIT OR Apache-2.0" @@ -26,7 +26,7 @@ default = ["chrono"] test = [] [target.'cfg(target_os = "windows")'.dependencies] -windows = { version = "0.48", features = [ +windows = { version = "0.52", features = [ "implement", "Win32_Foundation", "Win32_Security", @@ -34,6 +34,7 @@ windows = { version = "0.48", features = [ "Win32_System_Ole", "Win32_System_Rpc", "Win32_System_Wmi", + "Win32_System_Variant", ] } time = { version = "0.3", features = ["formatting", "parsing", "macros", "serde"], optional = true } chrono = { version = "0.4", features = ["clock", "std", "serde"], optional = true, default-features = false } diff --git a/src/async_query.rs b/src/async_query.rs index 172c8e5..f05d59c 100644 --- a/src/async_query.rs +++ b/src/async_query.rs @@ -39,7 +39,7 @@ impl WMIConnection { self.svc.ExecQueryAsync( &query_language, &query, - WBEM_FLAG_BIDIRECTIONAL.0 as _, + WBEM_FLAG_BIDIRECTIONAL, None, &p_sink_handle, )?; diff --git a/src/notification.rs b/src/notification.rs index 6b35b16..bc8215e 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -29,7 +29,7 @@ impl WMIConnection { self.svc.ExecNotificationQuery( &query_language, &query, - (WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY).0 as _, + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, None, )? }; @@ -168,7 +168,7 @@ impl WMIConnection { // As p_sink's RefCount = 1 before this call, // p_sink won't be dropped at the end of ExecNotificationQueryAsync self.svc - .ExecNotificationQueryAsync(&query_language, &query, 0, None, &p_sink_handle)? + .ExecNotificationQueryAsync(&query_language, &query, Default::default(), None, &p_sink_handle)? }; Ok(AsyncQueryResultStream::new( diff --git a/src/query.rs b/src/query.rs index df1888c..0ad34e7 100644 --- a/src/query.rs +++ b/src/query.rs @@ -430,7 +430,7 @@ impl WMIConnection { unsafe { self.svc.GetObject( &object_path, - WBEM_FLAG_RETURN_WBEM_COMPLETE.0 as _, + WBEM_FLAG_RETURN_WBEM_COMPLETE, None, Some(&mut pcls_obj), None, diff --git a/src/query_sink.rs b/src/query_sink.rs index 75d775e..7457a8b 100644 --- a/src/query_sink.rs +++ b/src/query_sink.rs @@ -326,7 +326,7 @@ mod tests { // As p_sink's RefCount = 1 before this call, // p_sink won't be dropped at the end of ExecNotificationQueryAsync con.svc - .ExecNotificationQueryAsync(&query_language, &query, 0, None, &p_sink) + .ExecNotificationQueryAsync(&query_language, &query, Default::default(), None, &p_sink) .unwrap() }; diff --git a/src/result_enumerator.rs b/src/result_enumerator.rs index 0bf21d2..5c71075 100644 --- a/src/result_enumerator.rs +++ b/src/result_enumerator.rs @@ -8,14 +8,14 @@ use serde::{ ser::{Error, SerializeMap}, Serialize, }; -use std::{convert::TryInto, ptr}; -use windows::core::{HSTRING, PCWSTR}; -use windows::Win32::System::Com::VARIANT; -use windows::Win32::System::Ole::{SafeArrayDestroy, VariantClear}; +use std::ptr; +use windows::{core::{HSTRING, PCWSTR}, Win32::System::Wmi::WBEM_CONDITION_FLAG_TYPE}; use windows::Win32::System::Wmi::{ IEnumWbemClassObject, IWbemClassObject, CIMTYPE_ENUMERATION, WBEM_FLAG_ALWAYS, WBEM_FLAG_NONSYSTEM_ONLY, WBEM_INFINITE, }; +use windows::Win32::System::Variant::{VARIANT, VariantClear}; +use windows::Win32::System::Ole::SafeArrayDestroy; /// A wrapper around a raw pointer to IWbemClassObject, which also takes care of releasing /// the object when dropped. @@ -37,7 +37,7 @@ impl IWbemClassWrapper { let p_names = unsafe { self.inner.GetNames( None, - WBEM_FLAG_ALWAYS.0 | WBEM_FLAG_NONSYSTEM_ONLY.0, + WBEM_CONDITION_FLAG_TYPE(WBEM_FLAG_ALWAYS.0 | WBEM_FLAG_NONSYSTEM_ONLY.0), ptr::null_mut(), ) }?; diff --git a/src/safearray.rs b/src/safearray.rs index a455952..e19585e 100644 --- a/src/safearray.rs +++ b/src/safearray.rs @@ -4,10 +4,11 @@ use crate::{ }; use std::{iter::Iterator, ptr::null_mut, slice}; use windows::core::BSTR; -use windows::Win32::System::Com::{self, SAFEARRAY, VARENUM, VT_BSTR}; use windows::Win32::System::Ole::{ SafeArrayAccessData, SafeArrayGetLBound, SafeArrayGetUBound, SafeArrayUnaccessData, }; +use windows::Win32::System::Variant::*; +use windows::Win32::System::Com::SAFEARRAY; #[derive(Debug)] pub struct SafeArrayAccessor<'a, T> { @@ -109,17 +110,17 @@ pub fn safe_array_to_vec(arr: &SAFEARRAY, item_type: VARENUM) -> WMIResult copy_type_to_vec(arr, Variant::I1), - Com::VT_I2 => copy_type_to_vec(arr, Variant::I2), - Com::VT_I4 => copy_type_to_vec(arr, Variant::I4), - Com::VT_I8 => copy_type_to_vec(arr, Variant::I8), - Com::VT_UI1 => copy_type_to_vec(arr, Variant::UI1), - Com::VT_UI2 => copy_type_to_vec(arr, Variant::UI2), - Com::VT_UI4 => copy_type_to_vec(arr, Variant::UI4), - Com::VT_UI8 => copy_type_to_vec(arr, Variant::UI8), - Com::VT_R4 => copy_type_to_vec(arr, Variant::R4), - Com::VT_R8 => copy_type_to_vec(arr, Variant::R8), - Com::VT_BSTR => { + VT_I1 => copy_type_to_vec(arr, Variant::I1), + VT_I2 => copy_type_to_vec(arr, Variant::I2), + VT_I4 => copy_type_to_vec(arr, Variant::I4), + VT_I8 => copy_type_to_vec(arr, Variant::I8), + VT_UI1 => copy_type_to_vec(arr, Variant::UI1), + VT_UI2 => copy_type_to_vec(arr, Variant::UI2), + VT_UI4 => copy_type_to_vec(arr, Variant::UI4), + VT_UI8 => copy_type_to_vec(arr, Variant::UI8), + VT_R4 => copy_type_to_vec(arr, Variant::R4), + VT_R8 => copy_type_to_vec(arr, Variant::R8), + VT_BSTR => { let mut items = vec![]; let accessor = unsafe { SafeArrayAccessor::::new(arr)? }; diff --git a/src/variant.rs b/src/variant.rs index 42311b8..e1e27a5 100644 --- a/src/variant.rs +++ b/src/variant.rs @@ -5,8 +5,8 @@ use serde::Serialize; use std::convert::TryFrom; use windows::core::{ComInterface, IUnknown, BSTR}; use windows::Win32::Foundation::{VARIANT_FALSE, VARIANT_TRUE}; -use windows::Win32::System::Com::{self, VARENUM, VARIANT, VT_ARRAY, VT_TYPEMASK}; use windows::Win32::System::Wmi::{self, IWbemClassObject, CIMTYPE_ENUMERATION}; +use windows::Win32::System::Variant::*; #[derive(Debug, PartialEq, Serialize)] #[serde(untagged)] @@ -98,42 +98,42 @@ impl Variant { // Rust can infer the return type of `vt.*Val()` calls, // but it's easier to read when the type is named explicitly. let variant_value = match variant_type { - Com::VT_BSTR => { + VT_BSTR => { let bstr_ptr: &BSTR = unsafe { &vt.Anonymous.Anonymous.Anonymous.bstrVal }; Variant::String(bstr_ptr.try_into()?) } - Com::VT_I1 => { + VT_I1 => { let num = unsafe { vt.Anonymous.Anonymous.Anonymous.cVal }; Variant::I1(num as _) } - Com::VT_I2 => { + VT_I2 => { let num: i16 = unsafe { vt.Anonymous.Anonymous.Anonymous.iVal }; Variant::I2(num) } - Com::VT_I4 => { + VT_I4 => { let num: i32 = unsafe { vt.Anonymous.Anonymous.Anonymous.lVal }; Variant::I4(num) } - Com::VT_I8 => { + VT_I8 => { let num: i64 = unsafe { vt.Anonymous.Anonymous.Anonymous.llVal }; Variant::I8(num) } - Com::VT_R4 => { + VT_R4 => { let num: f32 = unsafe { vt.Anonymous.Anonymous.Anonymous.fltVal }; Variant::R4(num) } - Com::VT_R8 => { + VT_R8 => { let num: f64 = unsafe { vt.Anonymous.Anonymous.Anonymous.dblVal }; Variant::R8(num) } - Com::VT_BOOL => { + VT_BOOL => { let value = unsafe { vt.Anonymous.Anonymous.Anonymous.boolVal }; match value { @@ -142,29 +142,29 @@ impl Variant { _ => return Err(WMIError::ConvertBoolError(value.0)), } } - Com::VT_UI1 => { + VT_UI1 => { let num: u8 = unsafe { vt.Anonymous.Anonymous.Anonymous.bVal }; Variant::UI1(num) } - Com::VT_UI2 => { + VT_UI2 => { let num: u16 = unsafe { vt.Anonymous.Anonymous.Anonymous.uiVal }; Variant::UI2(num) } - Com::VT_UI4 => { + VT_UI4 => { let num: u32 = unsafe { vt.Anonymous.Anonymous.Anonymous.ulVal }; Variant::UI4(num) } - Com::VT_UI8 => { + VT_UI8 => { let num: u64 = unsafe { vt.Anonymous.Anonymous.Anonymous.ullVal }; Variant::UI8(num) } - Com::VT_EMPTY => Variant::Empty, - Com::VT_NULL => Variant::Null, - Com::VT_UNKNOWN => { + VT_EMPTY => Variant::Empty, + VT_NULL => Variant::Null, + VT_UNKNOWN => { let unk = unsafe { &vt.Anonymous.Anonymous.Anonymous.punkVal }; let ptr = unk.as_ref().ok_or(WMIError::NullPointerResult)?; Variant::Unknown(IUnknownWrapper::new(ptr.clone()))