diff --git a/Cargo.toml b/Cargo.toml index 867aa3e..31dcd47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ default = ["chrono"] test = [] [target.'cfg(target_os = "windows")'.dependencies] -windows = { version = "0.44", features = [ +windows = { version = "0.48", features = [ "implement", "Win32_Foundation", "Win32_Security", @@ -46,7 +46,6 @@ log = "0.4" async-std = { version = "1.10", features = ["attributes"] } tokio = { version = "1.20.0", features = ["rt", "macros"] } serde_json = { version = "1.0" } -sys-locale = "0.2.1" criterion = "0.4" tempdir = "0.3" diff --git a/src/de/wbem_class_de.rs b/src/de/wbem_class_de.rs index 13aaf9c..d377a39 100644 --- a/src/de/wbem_class_de.rs +++ b/src/de/wbem_class_de.rs @@ -297,12 +297,12 @@ mod tests { assert_eq!(*w.get("Debug").unwrap(), Variant::Bool(false)); - let system_lang = sys_locale::get_locale().unwrap(); - let langs = w.get("MUILanguages").unwrap(); match langs { - Variant::Array(langs) => assert!(langs.contains(&Variant::String(system_lang))), + Variant::Array(langs) => { + assert!(matches!(langs[0], Variant::String(_))); + } _ => assert!(false), } } diff --git a/src/query_sink.rs b/src/query_sink.rs index 0a0ed26..75d775e 100644 --- a/src/query_sink.rs +++ b/src/query_sink.rs @@ -187,7 +187,7 @@ impl IWbemObjectSink_Impl for QuerySink { lFlags: i32, _hResult: HRESULT, _strParam: &BSTR, - _pObjParam: &Option, + _pObjParam: Option<&IWbemClassObject>, ) -> WinResult<()> { // SetStatus is called only once as flag=WBEM_FLAG_BIDIRECTIONAL in ExecQueryAsync // https://docs.microsoft.com/en-us/windows/win32/api/wbemcli/nf-wbemcli-iwbemobjectsink-setstatus @@ -209,7 +209,7 @@ mod tests { use super::*; use crate::tests::fixtures::*; use futures::StreamExt; - use windows::core::{IUnknown, Vtable}; + use windows::core::{ComInterface, IUnknown, Interface}; #[async_std::test] async fn async_it_should_send_result() { @@ -230,7 +230,7 @@ mod tests { // tests on ref count before Indicate call unsafe { - let test_ptr: IUnknown = raw_os.inner.clone().into(); + let test_ptr: IUnknown = raw_os.inner.clone().cast().unwrap(); let refcount = (test_ptr.vtable().AddRef)(std::mem::transmute_copy(&test_ptr)); // 1 from p_sink + 1 from test_ptr + 1 from AddRef assert_eq!(refcount, 3); @@ -241,12 +241,12 @@ mod tests { unsafe { p_sink - .Indicate(&[raw_os.inner.clone(), raw_os2.inner.clone()]) + .Indicate(&[Some(raw_os.inner.clone()), Some(raw_os2.inner.clone())]) .unwrap(); } // tests on ref count after Indicate call unsafe { - let test_ptr: IUnknown = raw_os.inner.clone().into(); + let test_ptr: IUnknown = raw_os.inner.clone().cast().unwrap(); let refcount = (test_ptr.vtable().AddRef)(std::mem::transmute_copy(&test_ptr)); // 1 from p_sink + 1 from test_ptr + 1 from AddRef + 1 from the Indicate call assert_eq!(refcount, 4); @@ -293,12 +293,10 @@ mod tests { let p_sink: IWbemObjectSink = sink.into(); let mut stream = AsyncQueryResultStream::new(stream, con.clone(), p_sink.clone()); - let mut arr = vec![std::ptr::null_mut()]; + let arr = vec![None]; - let result = unsafe { - (Vtable::vtable(&p_sink).Indicate)(Vtable::as_raw(&p_sink), 1, arr.as_mut_ptr()) - }; - assert_eq!(result, E_POINTER); + let result = unsafe { p_sink.Indicate(&arr) }; + assert_eq!(result.unwrap_err().code(), E_POINTER); let item = stream.next().await.unwrap(); diff --git a/src/result_enumerator.rs b/src/result_enumerator.rs index af0c3af..0bf21d2 100644 --- a/src/result_enumerator.rs +++ b/src/result_enumerator.rs @@ -9,7 +9,7 @@ use serde::{ Serialize, }; use std::{convert::TryInto, ptr}; -use windows::core::HSTRING; +use windows::core::{HSTRING, PCWSTR}; use windows::Win32::System::Com::VARIANT; use windows::Win32::System::Ole::{SafeArrayDestroy, VariantClear}; use windows::Win32::System::Wmi::{ @@ -57,8 +57,13 @@ impl IWbemClassWrapper { let mut cim_type = 0; unsafe { - self.inner - .Get(&name_prop, 0, &mut vt_prop, &mut cim_type, ptr::null_mut())?; + self.inner.Get( + PCWSTR::from_raw(name_prop.as_ptr()), + 0, + &mut vt_prop, + Some(&mut cim_type), + None, + )?; let property_value = Variant::from_variant(&vt_prop)? .convert_into_cim_type(CIMTYPE_ENUMERATION(cim_type))?; diff --git a/src/variant.rs b/src/variant.rs index 4977e17..42311b8 100644 --- a/src/variant.rs +++ b/src/variant.rs @@ -3,7 +3,7 @@ use crate::{ }; use serde::Serialize; use std::convert::TryFrom; -use windows::core::{IUnknown, Interface, BSTR}; +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}; @@ -106,7 +106,7 @@ impl Variant { Com::VT_I1 => { let num = unsafe { vt.Anonymous.Anonymous.Anonymous.cVal }; - Variant::I1(num.0 as _) + Variant::I1(num as _) } Com::VT_I2 => { let num: i16 = unsafe { vt.Anonymous.Anonymous.Anonymous.iVal };