Windows: simplify WMI query code

by making C++ code more C++
This commit is contained in:
李通洲
2022-10-16 23:58:13 +08:00
parent 5d5663e2a7
commit 38b3aae1e3
16 changed files with 254 additions and 346 deletions
+18 -27
View File
@@ -17,35 +17,26 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached)
ffStrbufInit(&cpu->name);
ffStrbufInit(&cpu->vendor);
IEnumWbemClassObject* pEnumerator = ffQueryWmi(L"SELECT Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors, ThreadCount, CurrentClockSpeed, MaxClockSpeed FROM Win32_Processor WHERE ProcessorType = 3", nullptr);
if(!pEnumerator)
FFWmiQuery query(L"SELECT Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors, ThreadCount, CurrentClockSpeed, MaxClockSpeed FROM Win32_Processor WHERE ProcessorType = 3");
if(!query)
return;
IWbemClassObject *pclsObj = NULL;
ULONG uReturn = 0;
if(FAILED(pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn)) || uReturn == 0)
if(FFWmiRecord record = query.next())
{
pEnumerator->Release();
return;
record.getString(L"Name", &cpu->name);
record.getString(L"Manufacturer", &cpu->vendor);
uint64_t value;
record.getUnsigned(L"NumberOfCores", &value);
cpu->coresPhysical = (uint16_t)value;
record.getUnsigned(L"NumberOfLogicalProcessors", &value);
cpu->coresLogical = (uint16_t)value;
record.getUnsigned(L"ThreadCount", &value);
cpu->coresOnline = (uint16_t)value;
record.getUnsigned(L"CurrentClockSpeed", &value); //There's no MinClockSpeed in Win32_Processor
cpu->frequencyMin = (double)value / 1000.0;
record.getUnsigned(L"MaxClockSpeed", &value);
cpu->frequencyMax = (double)value / 1000.0;
}
ffGetWmiObjString(pclsObj, L"Name", &cpu->name);
ffGetWmiObjString(pclsObj, L"Manufacturer", &cpu->vendor);
uint64_t value;
ffGetWmiObjUnsigned(pclsObj, L"NumberOfCores", &value);
cpu->coresPhysical = (uint16_t)value;
ffGetWmiObjUnsigned(pclsObj, L"NumberOfLogicalProcessors", &value);
cpu->coresLogical = (uint16_t)value;
ffGetWmiObjUnsigned(pclsObj, L"ThreadCount", &value);
cpu->coresOnline = (uint16_t)value;
ffGetWmiObjUnsigned(pclsObj, L"CurrentClockSpeed", &value); //There's no MinClockSpeed in Win32_Processor
cpu->frequencyMin = (double)value / 1000.0;
ffGetWmiObjUnsigned(pclsObj, L"MaxClockSpeed", &value);
cpu->frequencyMax = (double)value / 1000.0;
pclsObj->Release();
pEnumerator->Release();
}