I'm trying to go through all windows (using Windows API) and get a list of the windows, but when I try to pass through a vector as a LPARAM then I get an error:
- non-primitive cast: *mut Vec<isize> as LPARAM an as expression can only be used to convert between primitive types or to coerce to a specific trait object
Code:
unsafe {
let windows: Vec<isize> = vec![];
let _ = WindowsAndMessaging::EnumWindows(Some(enum_window), &mut windows as *mut Vec<isize> as LPARAM).ok();
};
The error diagnostic contains two vital pieces of information:
Either one is spot-on. With any
*mut _a primitive type, it necessarily means thatLPARAMisn't. And that is correct, too. Like most types that appear in the transformed API surface exposed by the windows crate,LPARAMfollows thenewtypeidiom.This prevents common errors where different types share the same underlying type (e.g.
HWNDandHDC), but also requires that clients construct values of the wrapper type. Casting won't work, as it would with the winapi or windows-sys crates (that use type aliases for primitive types instead).The second argument to
EnumWindowsneeds to be