Skip to content

Commit

Permalink
Merge pull request #72 from ohadravid/windows-0.46
Browse files Browse the repository at this point in the history
chore(deps): update windows requirement from 0.44 to 0.47
  • Loading branch information
ohadravid authored Apr 1, 2023
2 parents 1855dd0 + bb8d66d commit bb46515
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions src/de/wbem_class_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/query_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl IWbemObjectSink_Impl for QuerySink {
lFlags: i32,
_hResult: HRESULT,
_strParam: &BSTR,
_pObjParam: &Option<IWbemClassObject>,
_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
Expand All @@ -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() {
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();

Expand Down
11 changes: 8 additions & 3 deletions src/result_enumerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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))?;
Expand Down
4 changes: 2 additions & 2 deletions src/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit bb46515

Please sign in to comment.