Skip to content

Commit

Permalink
refactor: 🔨 Use HSTRING instead of OsString
Browse files Browse the repository at this point in the history
Use HSTRING when possible instead of OsString. HSTRING sometimes use OsString internally. If we have no other choice, we will use OsString and after that normal rust string
  • Loading branch information
AntwortEinesLebens committed Sep 15, 2024
1 parent 2084ceb commit 94e2e84
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/windows/processes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

use std::{
error::Error,
ffi::OsString,
fmt::{Display, Formatter, Result as FormatterResult},
os::windows::ffi::OsStringExt,
};
use windows::{
core::Owned,
core::{Owned, HSTRING},
Win32::{
Foundation::HANDLE,
System::Diagnostics::ToolHelp::{
Expand Down Expand Up @@ -43,14 +41,14 @@ pub fn get_pid(name: &str) -> Result<u32, Box<dyn Error>> {
}

loop {
if OsString::from_wide(
if HSTRING::from_wide(
process_entry
.szExeFile
.into_iter()
.take_while(|&byte| byte != 0)
.collect::<Vec<_>>()
.as_slice(),
) == name
)? == name
{
return Ok(process_entry.th32ProcessID);
}
Expand Down

0 comments on commit 94e2e84

Please sign in to comment.