I'm looking for a programmatic way of querying an Display Adapter's current power state (d-state) in Windows. It's not a USB device or ACPI device. I couldn't find much on how I could access the current d-state through cmd line or an API. It could also be seen in the device manager adapter's detail info.
Display Adapter's detail tab showing the device power state
logic that i have written :
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#pragma comment (lib, "SetupAPI.lib")
int DeviceManager::GetDeviceDriverPowerData() {
int res = 0;
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData = { sizeof(DeviceInfoData) };
// get device class information handle
hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_ADAPTER, 0, 0, DIGCF_PRESENT /*| DIGCF_PROFILE*/);
if (hDevInfo == INVALID_HANDLE_VALUE)
{
res = GetLastError();
return res;
}
// enumerute device information
DWORD required_size = 0;
for (int i = 0; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++)
{
DWORD DataT;
CM_POWER_DATA cmPowerData = { 0 };
// get device description information
if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_DEVICE_POWER_DATA, &DataT, (PBYTE)&cmPowerData, sizeof(cmPowerData), &req_bufsize))
{
res = GetLastError();
continue;
}
printf("PowerState:%d.\n", cmPowerData.PD_MostRecentPowerState);
}
return 0;
}
but it doesn't work .