Skip to content

Commit

Permalink
Bump windows crate to 0.52
Browse files Browse the repository at this point in the history
  • Loading branch information
ohadravid committed Jan 19, 2024
1 parent 1b35322 commit f59a44c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 41 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wmi"
version = "0.13.1"
version = "0.13.2"
authors = ["Ohad Ravid <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -26,14 +26,15 @@ default = ["chrono"]
test = []

[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.48", features = [
windows = { version = "0.52", features = [
"implement",
"Win32_Foundation",
"Win32_Security",
"Win32_System_Com",
"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 }
Expand Down
2 changes: 1 addition & 1 deletion src/async_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl WMIConnection {
self.svc.ExecQueryAsync(
&query_language,
&query,
WBEM_FLAG_BIDIRECTIONAL.0 as _,
WBEM_FLAG_BIDIRECTIONAL,
None,
&p_sink_handle,
)?;
Expand Down
11 changes: 8 additions & 3 deletions src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?
};
Expand Down Expand Up @@ -167,8 +167,13 @@ impl WMIConnection {
unsafe {
// 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)?
self.svc.ExecNotificationQueryAsync(
&query_language,
&query,
Default::default(),
None,
&p_sink_handle,
)?
};

Ok(AsyncQueryResultStream::new(
Expand Down
2 changes: 1 addition & 1 deletion src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion src/query_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,13 @@ 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()
};

Expand Down
13 changes: 8 additions & 5 deletions src/result_enumerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ 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::Win32::System::Ole::SafeArrayDestroy;
use windows::Win32::System::Variant::{VariantClear, VARIANT};
use windows::Win32::System::Wmi::{
IEnumWbemClassObject, IWbemClassObject, CIMTYPE_ENUMERATION, WBEM_FLAG_ALWAYS,
WBEM_FLAG_NONSYSTEM_ONLY, WBEM_INFINITE,
};
use windows::{
core::{HSTRING, PCWSTR},
Win32::System::Wmi::WBEM_CONDITION_FLAG_TYPE,
};

/// A wrapper around a raw pointer to IWbemClassObject, which also takes care of releasing
/// the object when dropped.
Expand All @@ -37,7 +40,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(),
)
}?;
Expand Down
25 changes: 13 additions & 12 deletions src/safearray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::Com::SAFEARRAY;
use windows::Win32::System::Ole::{
SafeArrayAccessData, SafeArrayGetLBound, SafeArrayGetUBound, SafeArrayUnaccessData,
};
use windows::Win32::System::Variant::*;

#[derive(Debug)]
pub struct SafeArrayAccessor<'a, T> {
Expand Down Expand Up @@ -109,17 +110,17 @@ pub fn safe_array_to_vec(arr: &SAFEARRAY, item_type: VARENUM) -> WMIResult<Vec<V
}

match item_type {
Com::VT_I1 => 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::<BSTR>::new(arr)? };

Expand Down
32 changes: 16 additions & 16 deletions src/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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::Variant::*;
use windows::Win32::System::Wmi::{self, IWbemClassObject, CIMTYPE_ENUMERATION};

#[derive(Debug, PartialEq, Serialize)]
Expand Down Expand Up @@ -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 {
Expand All @@ -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()))
Expand Down

0 comments on commit f59a44c

Please sign in to comment.