You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Questions about the use of the windows and windows-sys crates are best delegated to Stack Overflow.
As for the specific question: You shouldn't be using Foundation::CHAR here at all. Process32First returns strings encoded as ANSI (CP_ACP by default). That can quickly turn into sequences of bytes that do not represent valid UTF-8, and String::from_iter will respond with a panic!.
Instead, call Process32FirstW, which will populate a PROCESSENTRY32W structure. You can now convert the &[u16] into an OsString, if you so choose, or keep a 'raw' Vec<u16> around.
Rust just doesn't offer a convenient way to represent strings as used by Windows (UTF-16, but not necessarily well-formed). String handling is always going to feel unnatural with Rust on Windows: You'll either have lots of OsStrings, lots of fallible operations, or lots of opportunities for panic!s.
Note: there are some suggestions for making this marginally better in #1848. Please give your feedback there as we try to make string handling a little less painful.
I couldn't find an example on how to “correctly” convert Foundation::CHAR slices like szExeFile from ProcessEntry32 to a string.
My current solution looks like this
Is there a better solution for this or another preferred/intended way on how we should handle these?
The text was updated successfully, but these errors were encountered: