デバイス (cm_power_data_s) の電力データをフェッチしようとしています。そのためにAPIを
使用しています。これは一部のデバイスでは正常に機能しますが、他のデバイスでは機能しません。によって返されるデータはであり、これがないと を使用できません。 class を取得するためのクエリを作成して手動で入力しようとしましたが、バッファ サイズが返されません (null データを渡すのと同じです)。誰か助けてくれませんか?これが私のコードです:SetupDiGetDeviceRegistryProperty
SetupDiEnumDeviceInfo
null
SetupDiGetDeviceRegistryProperty
sp_devinfo_data
wmi
GUID
SetupDiGetDeviceRegistryProperty
uint SPDRP_DEVICE_POWER_DATA = 0x0000001E;
int proptype;
int size;
//int D3, D2, D1, D3wake, cap = 0;
DEVPROPKEY key = DEVPROPKEY.DEVPKEY_Device_PowerData;
IntPtr hDevInfo = SetupDiGetClassDevs(IntPtr.Zero, DevID, IntPtr.Zero, DIGCF.DIGCF_ALLCLASSES | DIGCF.DIGCF_PRESENT | DIGCF.DIGCF_DEVICEINTERFACE);
if (hDevInfo == (IntPtr)INVALID_HANDLE_VALUE)
{
throw new ArgumentNullException("invalidhandle");
}
SP_DEVINFO_DATA data = new SP_DEVINFO_DATA();
data.cbSize = Marshal.SizeOf(data);
SetupDiEnumDeviceInfo(hDevInfo, 0, ref data); // This data is empty for some devices
// SetupDiGetSelectedDevice(hDevInfo, ref data);
int aa = Marshal.GetLastWin32Error();
bool b = SetupDiGetDeviceRegistryProperty(hDevInfo, ref data, SPDRP_DEVICE_POWER_DATA, out proptype, IntPtr.Zero, 0, out size);
int a = Marshal.GetLastWin32Error();
if (size == 0)
{
return "";
// throw new ArgumentNullException("Power Data cannot be fetched");
}
IntPtr buffer1 = Marshal.AllocHGlobal(size);
if (!SetupDiGetDeviceRegistryProperty(hDevInfo, ref data, SPDRP_DEVICE_POWER_DATA, out proptype, buffer1, size, out size))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}