Here's a quick and dirty way to get the current CPU speed in Windows:
Code:
#include <stdio.h>
#include <windows.h>
#define CPU_KEY "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"
#define CPU_VALUE "~MHz"
int getMHz(void);
int main(void)
{
printf("Windows reports your computer is running at %dMHz\n", getMHz());
return 0;
}
int getMHz(void)
{
HKEY key;
DWORD type, size, mhz;
DWORD bufsiz = 4;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, CPU_KEY, 0, KEY_READ, &key)
!= ERROR_SUCCESS) {
/* Unable to open registry key */
return -2;
}
if (RegQueryValueEx(key, CPU_VALUE, NULL, &type, &mhz, &bufsiz)
!= ERROR_SUCCESS) {
/* Unable to query registry value */
return -1;
}
return mhz;
}
(don't know why it's putting those spaces at the end of the CPU_KEY string tdefine but they shouldn't be there)