I have been using windows api to get battery stats and i have figured out how to get battery data like chemistry using battery information but i cant figure out how to get stuff like manufacturer specs. Here is my current code
If anyone could give me one or two lines of code that would print that kind of data i would be very happy.
I found IOCTL_BATTERY_QUERY_INFORMATION to get the information i need but i cant figure out how to access that information from my current program.
#define INITGUID #include <windows.h> #include<batclass.h> #include<setupapi.h> #define GBS_HASBATTERY 0x1 #define GBS_ONBATTERY 0x2 #include<iostream> using namespace std; int main() { DWORD dwResult = GBS_ONBATTERY; HDEVINFO hdev = SetupDiGetClassDevs(&GUID_DEVICE_BATTERY, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); for (int idev = 0; idev < 100; idev++) { SP_DEVICE_INTERFACE_DATA did = {0}; did.cbSize = sizeof(did); if (SetupDiEnumDeviceInterfaces(hdev, 0, &GUID_DEVICE_BATTERY, idev, &did)) { DWORD cbRequired = 0; SetupDiGetDeviceInterfaceDetail(hdev, &did, 0, 0, &cbRequired, 0); if (ERROR_INSUFFICIENT_BUFFER == GetLastError()) { PSP_DEVICE_INTERFACE_DETAIL_DATA pdidd = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LPTR,cbRequired); if (pdidd) { pdidd->cbSize = sizeof(*pdidd); if (SetupDiGetDeviceInterfaceDetail(hdev,&did,pdidd,cbRequired,&cbRequired,0)) { HANDLE hBattery = CreateFile(pdidd->DevicePath,GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if (INVALID_HANDLE_VALUE != hBattery) { // Ask the battery for its tag. BATTERY_QUERY_INFORMATION bqi = {0}; DWORD dwWait = 0; DWORD dwOut; if (DeviceIoControl(hBattery, IOCTL_BATTERY_QUERY_TAG, &dwWait, sizeof(dwWait), &bqi.BatteryTag, sizeof(bqi.BatteryTag), &dwOut, NULL) && bqi.BatteryTag) { BATTERY_INFORMATION bi = {0}; bqi.InformationLevel = BatteryInformation; if (DeviceIoControl(hBattery, IOCTL_BATTERY_QUERY_INFORMATION, &bqi, sizeof(bqi), &bi, sizeof(bi), &dwOut, NULL)) { if (bi.Capabilities & BATTERY_SYSTEM_BATTERY) { if (!(bi.Capabilities & BATTERY_IS_SHORT_TERM)) { } BATTERY_WAIT_STATUS bws = {0}; bws.BatteryTag = bqi.BatteryTag; BATTERY_STATUS bs; if (DeviceIoControl(hBattery, IOCTL_BATTERY_QUERY_STATUS, &bws, sizeof(bws), &bs, sizeof(bs), &dwOut, NULL)) { if (bs.PowerState & BATTERY_POWER_ON_LINE) { dwResult &= ~GBS_ONBATTERY; } } } } } CloseHandle(hBattery); } } LocalFree(pdidd); } } } else if (ERROR_NO_MORE_ITEMS == GetLastError()) { break; // Enumeration failed - perhaps we're out of items } } SetupDiDestroyDeviceInfoList(hdev); }
If anyone could give me one or two lines of code that would print that kind of data i would be very happy.
I found IOCTL_BATTERY_QUERY_INFORMATION to get the information i need but i cant figure out how to access that information from my current program.