I always wanted to get the CPU clock speed in windows. After searching for a long time, I finally found the callntpowerinformation function. To use it, I must first include powrprof. h header file and link library powerprof. lib. but there are several problems:
First, powrprof. h, like many other header files in the Platform SDK, is still not verified by C ++. If you are not careful about including the header files in the C ++ program, there will still be a link error. It is better to include it like this:
Extern "C "{
# Include <powrprof. h>
}
The second reason is that there is a structure that does not know why it is not included in powrprof. H. This structure is processor_power_information. This problem still exists in Visual C ++ 2008 express edition. To get the correct processor speed, call callntpowerinformation. The processorinformation enumeration value is the first parameter. An array of the processor_power_information structure is used as the output cache (corresponding to each processor chip installed in the system ).
One solution is: this structure is defined in msdn, so we can define it in our own file:
typedef struct _PROCESSOR_POWER_INFORMATION { ULONG Number; ULONG MaxMhz; ULONG CurrentMhz; ULONG MhzLimit; ULONG MaxIdleState; ULONG CurrentIdleState;} PROCESSOR_POWER_INFORMATION , *PPROCESSOR_POWER_INFORMATION;
From the definition of the processor_power_information structure, you can find that this structure provides CPU speed information, such as the maximum speed, current speed, there is a related API function getpwucapabilities with the idle status (although I admit that I do not know the idle status bit-I will solve it), which can also achieve some system performance.