Here is my Rust code:
use std::mem::ManuallyDrop;
use windows::core::ComInterface;
use windows::Win32::System::Com::*;
use windows::Win32::UI::Shell::Common::ITEMIDLIST;
use windows::{core::Result, Win32::UI::Shell::*};
struct Com;
impl Drop for Com {
fn drop(&mut self) {
unsafe { CoUninitialize() };
}
}
struct Variant(VARIANT);
impl Drop for Variant {
fn drop(&mut self) {
unsafe {
match self.0.Anonymous.Anonymous.vt {
VT_BSTR => {
ManuallyDrop::drop(&mut ((*self.0.Anonymous.Anonymous).Anonymous.bstrVal))
}
VT_DISPATCH => {
ManuallyDrop::drop(&mut ((*self.0.Anonymous.Anonymous).Anonymous.pdispVal))
}
_ => (),
}
ManuallyDrop::drop(&mut self.0.Anonymous.Anonymous);
}
}
}
fn main() -> Result<()> {
unsafe {
CoInitialize(None)?;
let _com = Com;
//https://learn.microsoft.com/en-us/windows/win32/api/objbase/nf-objbase-createbindctx
let ibindctx = CreateBindCtx(0u32).unwrap();
let itemID_list = ITEMIDLIST::default();
let desktop_folder = SHGetDesktopFolder()?;
let pidl: [u16; 1] = [0x14]; // convert this into ITEMIDLIST
desktop_folder.BindToObject::<&IBindCtx>(&itemID_list, &ibindctx)?;
}
Ok(())
}
When I try to compile, I have the following error:
with the following toml dependencies:
[dependencies.windows]
version = "0.46"
features = [
"Win32_Foundation",
"Win32_System_Com",
"Win32_System_Ole",
"Win32_UI_Shell",
"Win32_UI_Shell_Common"
]
I have tried to follow the following documentation from Microsoft:
https://learn.microsoft.com/en-us/windows/win32/shell/folder-info#using-the-ishellfolder-interface
The purpose of this code is to convert a know PIDL from a folder to a display name. Unfortunately, the documentation of the windows crate is not beginner friendly.
Can someone help me, please?
I have tried to follow the C++ documentation of Microsoft for this function, without success.