diff --git a/LibreHardwareMonitorLib/Hardware/Battery/Battery.cs b/LibreHardwareMonitorLib/Hardware/Battery/Battery.cs index 773b343..24e4773 100644 --- a/LibreHardwareMonitorLib/Hardware/Battery/Battery.cs +++ b/LibreHardwareMonitorLib/Hardware/Battery/Battery.cs @@ -5,6 +5,7 @@ using System; using Windows.Win32; +using Windows.Win32.Foundation; using Windows.Win32.System.Power; using LibreHardwareMonitor.Interop; using Microsoft.Win32.SafeHandles; @@ -137,7 +138,7 @@ internal sealed class Battery : Hardware BATTERY_WAIT_STATUS bws = default; bws.BatteryTag = _batteryTag; BATTERY_STATUS batteryStatus = default; - if (PInvoke.DeviceIoControl(_batteryHandle, + if (PInvoke.DeviceIoControl((HANDLE)_batteryHandle.DangerousGetHandle(), PInvoke.IOCTL_BATTERY_QUERY_STATUS, &bws, (uint)sizeof(BATTERY_WAIT_STATUS), @@ -201,7 +202,7 @@ internal sealed class Battery : Hardware BATTERY_QUERY_INFORMATION bqi = default; bqi.BatteryTag = _batteryTag; bqi.InformationLevel = BATTERY_QUERY_INFORMATION_LEVEL.BatteryEstimatedTime; - if (PInvoke.DeviceIoControl(_batteryHandle, + if (PInvoke.DeviceIoControl((HANDLE)_batteryHandle.DangerousGetHandle(), PInvoke.IOCTL_BATTERY_QUERY_INFORMATION, &bqi, (uint)sizeof(BATTERY_QUERY_INFORMATION), @@ -222,7 +223,7 @@ internal sealed class Battery : Hardware uint temperature = 0; bqi.InformationLevel = BATTERY_QUERY_INFORMATION_LEVEL.BatteryTemperature; - if (PInvoke.DeviceIoControl(_batteryHandle, + if (PInvoke.DeviceIoControl((HANDLE)_batteryHandle.DangerousGetHandle(), PInvoke.IOCTL_BATTERY_QUERY_INFORMATION, &bqi, (uint)sizeof(BATTERY_QUERY_INFORMATION), diff --git a/LibreHardwareMonitorLib/Hardware/Battery/BatteryGroup.cs b/LibreHardwareMonitorLib/Hardware/Battery/BatteryGroup.cs index dd0ba03..45fa4fb 100644 --- a/LibreHardwareMonitorLib/Hardware/Battery/BatteryGroup.cs +++ b/LibreHardwareMonitorLib/Hardware/Battery/BatteryGroup.cs @@ -53,8 +53,8 @@ internal class BatteryGroup : IGroup { uint cbRequired = 0; - PInvoke.SetupDiGetDeviceInterfaceDetail(hdev, - data, + PInvoke.SetupDiGetDeviceInterfaceDetail((HDEVINFO)hdev.DangerousGetHandle(), + &data, null, 0, &cbRequired, @@ -63,19 +63,19 @@ internal class BatteryGroup : IGroup if (Marshal.GetLastWin32Error() == (int)WIN32_ERROR.ERROR_INSUFFICIENT_BUFFER) { IntPtr buffer = Marshal.AllocHGlobal((int)cbRequired); - SP_DEVICE_INTERFACE_DETAIL_DATA_W* pData = (SP_DEVICE_INTERFACE_DETAIL_DATA_W*)buffer; - pData->cbSize = (uint)sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W); + SP_DEVICE_INTERFACE_DETAIL_DATA_W* pDetailData = (SP_DEVICE_INTERFACE_DETAIL_DATA_W*)buffer; + pDetailData->cbSize = (uint)sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W); - if (PInvoke.SetupDiGetDeviceInterfaceDetail(hdev, - data, - pData, + if (PInvoke.SetupDiGetDeviceInterfaceDetail((HDEVINFO)hdev.DangerousGetHandle(), + &data, + pDetailData, cbRequired, &cbRequired, null)) { string devicePath; - fixed (void* pDevicePath = &pData->DevicePath.e0) + fixed (void* pDevicePath = &pDetailData->DevicePath.e0) devicePath = new string((char*)pDevicePath); SafeFileHandle battery = PInvoke.CreateFile(devicePath, (uint)FileAccess.ReadWrite, FILE_SHARE_MODE.FILE_SHARE_READ | FILE_SHARE_MODE.FILE_SHARE_WRITE, null, FILE_CREATION_DISPOSITION.OPEN_EXISTING, FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_NORMAL, null); @@ -85,7 +85,7 @@ internal class BatteryGroup : IGroup uint dwWait = 0; uint bytesReturned = 0; - if (PInvoke.DeviceIoControl(battery, + if (PInvoke.DeviceIoControl((HANDLE)battery.DangerousGetHandle(), PInvoke.IOCTL_BATTERY_QUERY_TAG, &dwWait, sizeof(uint), @@ -97,7 +97,7 @@ internal class BatteryGroup : IGroup BATTERY_INFORMATION bi = default; bqi.InformationLevel = BATTERY_QUERY_INFORMATION_LEVEL.BatteryInformation; - if (PInvoke.DeviceIoControl(battery, + if (PInvoke.DeviceIoControl((HANDLE)battery.DangerousGetHandle(), PInvoke.IOCTL_BATTERY_QUERY_INFORMATION, &bqi, (uint)sizeof(BATTERY_QUERY_INFORMATION), @@ -145,7 +145,7 @@ internal class BatteryGroup : IGroup { uint returnBytes = 0; - if (PInvoke.DeviceIoControl(battery, + if (PInvoke.DeviceIoControl((HANDLE)battery.DangerousGetHandle(), PInvoke.IOCTL_BATTERY_QUERY_INFORMATION, &bqi, (uint)sizeof(BATTERY_QUERY_INFORMATION), diff --git a/LibreHardwareMonitorLib/Hardware/Storage/AbstractStorage.cs b/LibreHardwareMonitorLib/Hardware/Storage/AbstractStorage.cs index 5f9dcac..2092e25 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/AbstractStorage.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/AbstractStorage.cs @@ -10,6 +10,7 @@ using System.Globalization; using System.IO; using System.Text; using Windows.Win32; +using Windows.Win32.Foundation; using Windows.Win32.Storage.FileSystem; using Windows.Win32.System.Ioctl; using LibreHardwareMonitor.Interop; @@ -184,7 +185,7 @@ public abstract class AbstractStorage : Hardware DISK_PERFORMANCE diskPerformance = new(); uint bytesReturned; - if (!PInvoke.DeviceIoControl(_storageInfo.Handle, PInvoke.IOCTL_DISK_PERFORMANCE, null, 0, &diskPerformance, (uint)sizeof(DISK_PERFORMANCE), &bytesReturned, null)) + if (!PInvoke.DeviceIoControl((HANDLE)_storageInfo.Handle.DangerousGetHandle(), PInvoke.IOCTL_DISK_PERFORMANCE, null, 0, &diskPerformance, (uint)sizeof(DISK_PERFORMANCE), &bytesReturned, null)) { return; } diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs index 25f3767..cd8ea5b 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs @@ -7,6 +7,7 @@ using System; using System.IO; using System.Runtime.InteropServices; using Windows.Win32; +using Windows.Win32.Foundation; using Windows.Win32.Storage.FileSystem; using Windows.Win32.Storage.IscsiDisc; using Windows.Win32.Storage.Nvme; @@ -56,7 +57,7 @@ internal class NVMeIntel : INVMeDrive IntPtr buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(passThrough, buffer, false); - bool validTransfer = PInvoke.DeviceIoControl(hDevice, PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)hDevice.DangerousGetHandle(), PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); if (validTransfer) { IntPtr offset = Marshal.OffsetOf(nameof(AtaSmart.NVME_PASS_THROUGH_IOCTL.DataBuffer)); @@ -105,7 +106,7 @@ internal class NVMeIntel : INVMeDrive IntPtr buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(passThrough, buffer, false); - bool validTransfer = PInvoke.DeviceIoControl(hDevice, PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)hDevice.DangerousGetHandle(), PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); if (validTransfer) { IntPtr offset = Marshal.OffsetOf(nameof(AtaSmart.NVME_PASS_THROUGH_IOCTL.DataBuffer)); @@ -157,7 +158,7 @@ internal class NVMeIntel : INVMeDrive IntPtr buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(passThrough, buffer, false); - bool validTransfer = PInvoke.DeviceIoControl(handle, PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)handle.DangerousGetHandle(), PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); Marshal.FreeHGlobal(buffer); if (validTransfer) diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs index c0560bd..81344f4 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs @@ -9,6 +9,7 @@ using System.Runtime.InteropServices; using LibreHardwareMonitor.Interop; using Microsoft.Win32.SafeHandles; using Windows.Win32; +using Windows.Win32.Foundation; using Windows.Win32.Storage.FileSystem; using Windows.Win32.Storage.IscsiDisc; using Windows.Win32.Storage.Nvme; @@ -56,7 +57,7 @@ internal class NVMeIntelRst : INVMeDrive IntPtr buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(passThrough, buffer, false); - bool validTransfer = PInvoke.DeviceIoControl(hDevice, PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)hDevice.DangerousGetHandle(), PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); if (validTransfer) { IntPtr offset = Marshal.OffsetOf(nameof(AtaSmart.NVME_PASS_THROUGH_IOCTL.DataBuffer)); @@ -105,7 +106,7 @@ internal class NVMeIntelRst : INVMeDrive IntPtr buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(passThrough, buffer, false); - bool validTransfer = PInvoke.DeviceIoControl(hDevice, PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)hDevice.DangerousGetHandle(), PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); if (validTransfer) { IntPtr offset = Marshal.OffsetOf(nameof(AtaSmart.NVME_PASS_THROUGH_IOCTL.DataBuffer)); @@ -157,7 +158,7 @@ internal class NVMeIntelRst : INVMeDrive IntPtr buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(passThrough, buffer, false); - bool validTransfer = PInvoke.DeviceIoControl(handle, PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)handle.DangerousGetHandle(), PInvoke.IOCTL_SCSI_MINIPORT, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); Marshal.FreeHGlobal(buffer); if (validTransfer) diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeSamsung.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeSamsung.cs index cb8bcfa..5ca1883 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeSamsung.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeSamsung.cs @@ -9,6 +9,7 @@ using System.Runtime.InteropServices; using LibreHardwareMonitor.Interop; using Microsoft.Win32.SafeHandles; using Windows.Win32; +using Windows.Win32.Foundation; using Windows.Win32.Storage.FileSystem; using Windows.Win32.Storage.IscsiDisc; using Windows.Win32.Storage.Nvme; @@ -56,7 +57,7 @@ internal class NVMeSamsung : INVMeDrive int length = (int)(Marshal.OffsetOf(typeof(AtaSmart.SCSI_PASS_THROUGH), nameof(AtaSmart.SCSI_PASS_THROUGH.DataBuf)).ToInt32() + buffers.Spt.DataTransferLength); IntPtr buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(buffers, buffer, false); - bool validTransfer = PInvoke.DeviceIoControl(hDevice, PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)hDevice.DangerousGetHandle(), PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); Marshal.FreeHGlobal(buffer); bool result = false; @@ -86,7 +87,7 @@ internal class NVMeSamsung : INVMeDrive buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(buffers, buffer, false); - validTransfer = PInvoke.DeviceIoControl(hDevice, PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + validTransfer = PInvoke.DeviceIoControl((HANDLE)hDevice.DangerousGetHandle(), PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); buffers = Marshal.PtrToStructure(buffer); @@ -138,7 +139,7 @@ internal class NVMeSamsung : INVMeDrive int length = Marshal.SizeOf(); IntPtr buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(buffers, buffer, false); - bool validTransfer = PInvoke.DeviceIoControl(hDevice, PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)hDevice.DangerousGetHandle(), PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); Marshal.FreeHGlobal(buffer); if (validTransfer) @@ -166,7 +167,7 @@ internal class NVMeSamsung : INVMeDrive buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(buffers, buffer, false); - validTransfer = PInvoke.DeviceIoControl(hDevice, PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + validTransfer = PInvoke.DeviceIoControl((HANDLE)hDevice.DangerousGetHandle(), PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); if (validTransfer) { IntPtr offset = Marshal.OffsetOf(nameof(AtaSmart.SCSI_PASS_THROUGH.DataBuf)); @@ -219,7 +220,7 @@ internal class NVMeSamsung : INVMeDrive int length = Marshal.SizeOf(); IntPtr buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(buffers, buffer, false); - bool validTransfer = PInvoke.DeviceIoControl(handle, PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)handle.DangerousGetHandle(), PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); Marshal.FreeHGlobal(buffer); if (validTransfer) @@ -247,7 +248,7 @@ internal class NVMeSamsung : INVMeDrive buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(buffers, buffer, false); - validTransfer = PInvoke.DeviceIoControl(handle, PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); + validTransfer = PInvoke.DeviceIoControl((HANDLE)handle.DangerousGetHandle(), PInvoke.IOCTL_SCSI_PASS_THROUGH, (void*)buffer, (uint)length, (void*)buffer, (uint)length, null, null); if (validTransfer) { AtaSmart.SCSI_PASS_THROUGH result = Marshal.PtrToStructure(buffer); diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeWindows.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeWindows.cs index eb18e48..ea8ce4d 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeWindows.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeWindows.cs @@ -9,6 +9,7 @@ using System.Runtime.InteropServices; using LibreHardwareMonitor.Interop; using Microsoft.Win32.SafeHandles; using Windows.Win32; +using Windows.Win32.Foundation; using Windows.Win32.Storage.FileSystem; using Windows.Win32.Storage.Nvme; using Windows.Win32.System.Ioctl; @@ -46,7 +47,7 @@ internal class NVMeWindows : INVMeDrive protocolData->ProtocolDataOffset = (uint)sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA); protocolData->ProtocolDataLength = (uint)sizeof(NVME_IDENTIFY_CONTROLLER_DATA); - bool validTransfer = PInvoke.DeviceIoControl(hDevice, PInvoke.IOCTL_STORAGE_QUERY_PROPERTY, (void*)ptr, (uint)cb, (void*)ptr, (uint)cb, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)hDevice.DangerousGetHandle(), PInvoke.IOCTL_STORAGE_QUERY_PROPERTY, (void*)ptr, (uint)cb, (void*)ptr, (uint)cb, null, null); if (validTransfer) { var dataDescriptor = (STORAGE_PROTOCOL_DATA_DESCRIPTOR*)ptr; @@ -86,7 +87,7 @@ internal class NVMeWindows : INVMeDrive protocolData->ProtocolDataOffset = (uint)sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA); protocolData->ProtocolDataLength = (uint)sizeof(NVME_HEALTH_INFO_LOG); - bool validTransfer = PInvoke.DeviceIoControl(hDevice, PInvoke.IOCTL_STORAGE_QUERY_PROPERTY, (void*)ptr, (uint)cb, (void*)ptr, (uint)cb, null, null); + bool validTransfer = PInvoke.DeviceIoControl((HANDLE)hDevice.DangerousGetHandle(), PInvoke.IOCTL_STORAGE_QUERY_PROPERTY, (void*)ptr, (uint)cb, (void*)ptr, (uint)cb, null, null); if (validTransfer) { var dataDescriptor = (STORAGE_PROTOCOL_DATA_DESCRIPTOR*)ptr; diff --git a/LibreHardwareMonitorLib/Hardware/Storage/WindowsSmart.cs b/LibreHardwareMonitorLib/Hardware/Storage/WindowsSmart.cs index b7e0f50..5ce7565 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/WindowsSmart.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/WindowsSmart.cs @@ -10,6 +10,7 @@ using System.Runtime.InteropServices; using System.Text; using LibreHardwareMonitor.Interop; using Windows.Win32; +using Windows.Win32.Foundation; using Windows.Win32.Storage.FileSystem; using Windows.Win32.System.Ioctl; using static LibreHardwareMonitor.Interop.AtaSmart; @@ -59,7 +60,7 @@ internal class WindowsSmart : ISmart var result = new SENDCMDOUTPARAMS(); - return PInvoke.DeviceIoControl(_handle, + return PInvoke.DeviceIoControl((HANDLE)_handle.DangerousGetHandle(), PInvoke.SMART_SEND_DRIVE_COMMAND, ¶meter, (uint)sizeof(SENDCMDINPARAMS), @@ -89,7 +90,7 @@ internal class WindowsSmart : ISmart int cb = sizeof(SENDCMDOUTPARAMS) + 512; // 512 bytes buffer. IntPtr buffer = Marshal.AllocHGlobal(cb); - bool isValid = PInvoke.DeviceIoControl(_handle, + bool isValid = PInvoke.DeviceIoControl((HANDLE)_handle.DangerousGetHandle(), PInvoke.SMART_RCV_DRIVE_DATA, ¶meter, (uint)sizeof(SENDCMDINPARAMS), @@ -139,7 +140,7 @@ internal class WindowsSmart : ISmart int cb = sizeof(SENDCMDOUTPARAMS) + 512; // 2 bytes padding + 512 bytes buffer. IntPtr buffer = Marshal.AllocHGlobal(cb); - bool isValid = PInvoke.DeviceIoControl(_handle, + bool isValid = PInvoke.DeviceIoControl((HANDLE)_handle.DangerousGetHandle(), PInvoke.SMART_RCV_DRIVE_DATA, ¶meter, (uint)sizeof(SENDCMDINPARAMS), @@ -186,7 +187,7 @@ internal class WindowsSmart : ISmart int cb = sizeof(SENDCMDOUTPARAMS) + sizeof(IDENTIFY_DEVICE_DATA); IntPtr buffer = Marshal.AllocHGlobal(cb); - bool valid = PInvoke.DeviceIoControl(_handle, + bool valid = PInvoke.DeviceIoControl((HANDLE)_handle.DangerousGetHandle(), PInvoke.SMART_RCV_DRIVE_DATA, ¶meter, (uint)sizeof(SENDCMDINPARAMS), diff --git a/LibreHardwareMonitorLib/Hardware/Storage/WindowsStorage.cs b/LibreHardwareMonitorLib/Hardware/Storage/WindowsStorage.cs index a70bff7..69c8fe8 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/WindowsStorage.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/WindowsStorage.cs @@ -9,6 +9,7 @@ using System.IO; using System.Management; using System.Runtime.InteropServices; using Windows.Win32; +using Windows.Win32.Foundation; using Windows.Win32.Storage.FileSystem; using Windows.Win32.System.Ioctl; using Microsoft.Win32.SafeHandles; @@ -33,7 +34,7 @@ internal static class WindowsStorage var query = new STORAGE_PROPERTY_QUERY { PropertyId = STORAGE_PROPERTY_ID.StorageDeviceProperty, QueryType = STORAGE_QUERY_TYPE.PropertyStandardQuery }; STORAGE_DESCRIPTOR_HEADER result = new(); - if (!PInvoke.DeviceIoControl(handle, PInvoke.IOCTL_STORAGE_QUERY_PROPERTY, &query, (uint)sizeof(STORAGE_PROPERTY_QUERY), &result, (uint)sizeof(STORAGE_DESCRIPTOR_HEADER), null, null)) + if (!PInvoke.DeviceIoControl((HANDLE)handle.DangerousGetHandle(), PInvoke.IOCTL_STORAGE_QUERY_PROPERTY, &query, (uint)sizeof(STORAGE_PROPERTY_QUERY), &result, (uint)sizeof(STORAGE_DESCRIPTOR_HEADER), null, null)) { return null; } @@ -42,7 +43,7 @@ internal static class WindowsStorage try { - return PInvoke.DeviceIoControl(handle, PInvoke.IOCTL_STORAGE_QUERY_PROPERTY, &query, (uint)sizeof(STORAGE_PROPERTY_QUERY), (void*)descriptorPtr, result.Size, null, null) + return PInvoke.DeviceIoControl((HANDLE)handle.DangerousGetHandle(), PInvoke.IOCTL_STORAGE_QUERY_PROPERTY, &query, (uint)sizeof(STORAGE_PROPERTY_QUERY), (void*)descriptorPtr, result.Size, null, null) ? new StorageInfo((int)driveIndex, descriptorPtr) : null; } diff --git a/LibreHardwareMonitorLib/LibreHardwareMonitorLib.csproj b/LibreHardwareMonitorLib/LibreHardwareMonitorLib.csproj index b3d27d1..43107a5 100644 --- a/LibreHardwareMonitorLib/LibreHardwareMonitorLib.csproj +++ b/LibreHardwareMonitorLib/LibreHardwareMonitorLib.csproj @@ -38,12 +38,12 @@ - - - - - - + + + + + + @@ -56,7 +56,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/LibreHardwareMonitorLib/PawnIo/PawnIo.cs b/LibreHardwareMonitorLib/PawnIo/PawnIo.cs index 295c3d3..38f3eab 100644 --- a/LibreHardwareMonitorLib/PawnIo/PawnIo.cs +++ b/LibreHardwareMonitorLib/PawnIo/PawnIo.cs @@ -83,7 +83,7 @@ public class PawnIo fixed (byte* pIn = bin) { - if (PInvoke.DeviceIoControl(handle, (uint)ControlCode.LoadBinary, pIn, (uint)bin.Length, null, 0u, null, null)) + if (PInvoke.DeviceIoControl((HANDLE)handle.DangerousGetHandle(), (uint)ControlCode.LoadBinary, pIn, (uint)bin.Length, null, 0u, null, null)) return new PawnIo(handle); } @@ -109,7 +109,7 @@ public class PawnIo fixed (byte* pIn = totalInput, pOut = output) { - if (PInvoke.DeviceIoControl(_handle, (uint)ControlCode.Execute, pIn, (uint)totalInput.Length, pOut, (uint)output.Length, &read, null)) + if (PInvoke.DeviceIoControl((HANDLE)_handle.DangerousGetHandle(), (uint)ControlCode.Execute, pIn, (uint)totalInput.Length, pOut, (uint)output.Length, &read, null)) { long[] outp = new long[read / sizeof(long)]; Buffer.BlockCopy(output, 0, outp, 0, (int)read); @@ -144,7 +144,7 @@ public class PawnIo fixed (byte* pIn = totalInput, pOut = output) { - if (PInvoke.DeviceIoControl(_handle, (uint)ControlCode.Execute, pIn, (uint)totalInput.Length, pOut, (uint)output.Length, &read, null)) + if (PInvoke.DeviceIoControl((HANDLE)_handle.DangerousGetHandle(), (uint)ControlCode.Execute, pIn, (uint)totalInput.Length, pOut, (uint)output.Length, &read, null)) { Buffer.BlockCopy(output, 0, outBuffer, 0, Math.Min((int)read, outBuffer.Length * sizeof(long))); returnSize = read / sizeof(long);