try cpu once more

This commit is contained in:
2025-08-02 14:40:14 +02:00
parent e718dcef65
commit cb1c2b0921

View File

@@ -470,7 +470,7 @@ fn get_cpu_temp() -> Option<f32> {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
use com::runtime::init_runtime; use com::runtime::init_runtime;
use com::sys::{CLSCTX_INPROC_SERVER, COINIT_MULTITHREADED}; use com::sys::{CLSCTX_INPROC_SERVER, COINIT_MULTITHREADED, FAILED};
use widestring::U16CString; use widestring::U16CString;
use winapi::shared::rpcdce::*; use winapi::shared::rpcdce::*;
use winapi::shared::wtypes::VT_I4; use winapi::shared::wtypes::VT_I4;
@@ -560,12 +560,24 @@ fn get_cpu_temp() -> Option<f32> {
let mut obj: *mut wbemcli::IWbemClassObject = std::ptr::null_mut(); let mut obj: *mut wbemcli::IWbemClassObject = std::ptr::null_mut();
let mut returned = 0; let mut returned = 0;
let hr = (*enumerator).Next( let hr = (*enumerator).Next(
wbemcli::WBEM_INFINITE.try_into().unwrap(), wbemcli::WBEM_INFINITE as i32, // Fixed: cast directly to i32
1, 1,
&mut obj, &mut obj,
&mut returned, &mut returned,
); );
if FAILED(hr) {
eprintln!("Failed to enumerate WMI objects (HRESULT: {})", hr);
(*enumerator).Release();
continue;
}
if returned == 0 {
// No more items
(*enumerator).Release();
continue;
}
if hr == 0 && returned > 0 { if hr == 0 && returned > 0 {
let mut variant = std::mem::zeroed::<VARIANT>(); let mut variant = std::mem::zeroed::<VARIANT>();
// Try different possible property names // Try different possible property names