I am trying to call the PathCompactPathExW function from Rust using the windows crate.
Function signature:
windows::Win32::UI::Shell
pub unsafe fn PathCompactPathExW<P0>(pszout: &mut [u16], pszsrc: P0, dwflags: u32) -> super::super::Foundation::BOOL
where
P0: windows_core::Param<windows_core::PCWSTR>,
I wrote the following code to call the function.
let path = &"path to file".to_string();
let mut pszout = vec![0u16; 33000];
let pszsrc = unsafe {
windows_core::Param::Owned(PCWSTR::from_raw(
path.encode_utf16()
.chain([0u16])
.collect::<Vec<u16>>()
.as_ptr(),
))
};
let result: windows::Win32::Foundation::BOOL =
unsafe { PathCompactPathExW(&mut pszout, pszsrc, 0) };
When I compile the above code, I get the following error
type mismatch resolving `<Param<PCWSTR> as TypeKind>::TypeKind == CopyType`
required for `windows_core::Param<windows_core::PCWSTR>` to implement `core::param::Param<windows_strings::pcwstr::PCWSTR, core::r#type::CopyType>`r
I have no idea how to specify the correct second argument.
What is the correct way to call a function?
New contributor
末永克 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.