You could use the api of Performance Counters. Check the following sample,
#include <windows.h>
#include <iostream>
#include <pdh.h>
#pragma comment(lib, "pdh.lib")
int main()
{
PDH_HQUERY cpuQuery;
PDH_HCOUNTER cpuTotal;
PdhOpenQuery(NULL, NULL, &cpuQuery);
PdhAddCounter(cpuQuery, L"\\Processor(_Total)\\% Processor Time", NULL, &cpuTotal);
PdhCollectQueryData(cpuQuery);
DWORD time = 1000;
for(;;)
{
Sleep(time);
PDH_FMT_COUNTERVALUE counterVal;
PdhCollectQueryData(cpuQuery);
PdhGetFormattedCounterValue(cpuTotal, PDH_FMT_DOUBLE, NULL, &counterVal);
printf("%f\n", counterVal.doubleValue);
}
return 0;
}
Or refer to the sample on MSDN: Browsing Performance Counters