我使用的是Windows crate 中的IDesktopWallpaper::SetWallpaper
方法.此方法的第二个参数是PCWSTR
(指针),指向要设置为墙纸的图像的完整路径.问题是PCWSTR
对象的类型应该是*const u16
,而不是*const String
.如何从路径/字符串中获取PCWSTR
对象?
let path = "Path_to_image.jpg".to_string();
let ptr = &path as *const String;
let wallpaper = PCWSTR::from_raw(ptr);
// ^^^ expected raw pointer `*const u16`
// found raw pointer `*const String`
unsafe { desktop.SetWallpaper(None, wallpaper)};