1515static const char * detectWithCmApi (FFBatteryOptions * options , FFlist * results ) {
1616 // https://learn.microsoft.com/en-us/windows-hardware/drivers/install/using-device-interfaces
1717 ULONG cchDeviceInterfaces = 0 ;
18- CONFIGRET cr = CM_Get_Device_Interface_List_SizeW (& cchDeviceInterfaces , (LPGUID ) & GUID_DEVCLASS_BATTERY , NULL , CM_GET_DEVICE_INTERFACE_LIST_PRESENT );
19- if (cr != CR_SUCCESS ) {
18+ if (CM_Get_Device_Interface_List_SizeW (
19+ & cchDeviceInterfaces ,
20+ (LPGUID ) & GUID_DEVCLASS_BATTERY ,
21+ NULL ,
22+ CM_GET_DEVICE_INTERFACE_LIST_PRESENT ) != CR_SUCCESS ) {
2023 return "CM_Get_Device_Interface_List_SizeW() failed" ;
2124 }
2225
@@ -25,14 +28,18 @@ static const char* detectWithCmApi(FFBatteryOptions* options, FFlist* results) {
2528 }
2629
2730 wchar_t * FF_AUTO_FREE mszDeviceInterfaces = (wchar_t * ) malloc (cchDeviceInterfaces * sizeof (wchar_t ));
28- cr = CM_Get_Device_Interface_ListW ((LPGUID ) & GUID_DEVCLASS_BATTERY , NULL , mszDeviceInterfaces , cchDeviceInterfaces , CM_GET_DEVICE_INTERFACE_LIST_PRESENT );
29- if (cr != CR_SUCCESS ) {
31+ if (CM_Get_Device_Interface_ListW (
32+ (LPGUID ) & GUID_DEVCLASS_BATTERY ,
33+ NULL ,
34+ mszDeviceInterfaces ,
35+ cchDeviceInterfaces ,
36+ CM_GET_DEVICE_INTERFACE_LIST_PRESENT ) != CR_SUCCESS ) {
3037 return "CM_Get_Device_Interface_ListW() failed" ;
3138 }
3239
33- for (const wchar_t * pDeviceInterface = mszDeviceInterfaces ; * pDeviceInterface ; pDeviceInterface += wcslen (pDeviceInterface ) + 1 ) {
40+ for (const wchar_t * p = mszDeviceInterfaces ; * p ; p += wcslen (p ) + 1 ) {
3441 HANDLE FF_AUTO_CLOSE_FD hBattery =
35- CreateFileW (pDeviceInterface , GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
42+ CreateFileW (p , GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
3643
3744 if (hBattery == INVALID_HANDLE_VALUE ) {
3845 continue ;
0 commit comments