Here's an example: https://github.com/microsoft/windows-rs/issues/2648#issuecomment-1715813708
Error while creating SAFEARRAY using Windows Rust crate.
Sanil Raut
0
Reputation points Microsoft Employee
Hi,
I am trying to create a safearray of type BSTR and add one BSTR Variant to it with windows rust crate: https://github.com/microsoft/windows-rs (windows = "0.48.0")
pub fn createSafeArray() {
unsafe {
let mut var = VARIANT::default();
(*var.Anonymous.Anonymous).vt = VT_BSTR;
(*var.Anonymous.Anonymous).Anonymous.bstrVal =
ManuallyDrop::new(BSTR::from("3"));
// Create SAFEARRAY of type BSTR
/*
let safearray = SafeArrayCreate(
Com::VT_BSTR,
1,
&SAFEARRAYBOUND {
cElements: 1,
lLbound: 0,
},
); */
let safearray = SafeArrayCreateVector(VT_BSTR, 0, 1);
// Add to safe array
let res = SafeArrayPutElement(
safearray,
0 as _,
&test as *const Com::VARIANT as *const c_void,
);
println!("Res: {:#?}", res);
}
}
And getting the following error
Err(
Error {
code: HRESULT(0x80070057),
message: "The parameter is incorrect.",
},
)
Is there anything wrong or missing in the above code?
Windows development Windows API - Win32
2,782 questions