-
January 7th, 2012, 11:44 AM
#1
Windows SDK: How to get the processor frequency?
Q: How to get the processor(s) frequency?
A: One simple method is by using CallNtPowerInformation.
Example
Code:
#include <NTstatus.h>
#define WIN32_NO_STATUS
#include <windows.h>
#include <Powrprof.h>
#include <iostream>
typedef struct _PROCESSOR_POWER_INFORMATION {
ULONG Number;
ULONG MaxMhz;
ULONG CurrentMhz;
ULONG MhzLimit;
ULONG MaxIdleState;
ULONG CurrentIdleState;
} PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;
#pragma comment(lib, "Powrprof.lib")
int main()
{
// get the number or processors
SYSTEM_INFO si = {0};
::GetSystemInfo(&si);
// allocate buffer to get info for each processor
const int size = si.dwNumberOfProcessors * sizeof(PROCESSOR_POWER_INFORMATION);
LPBYTE pBuffer = new BYTE[size];
NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, pBuffer, size);
if(STATUS_SUCCESS == status)
{
// list each processor frequency
PPROCESSOR_POWER_INFORMATION ppi = (PPROCESSOR_POWER_INFORMATION)pBuffer;
for(DWORD nIndex = 0; nIndex < si.dwNumberOfProcessors; nIndex++)
{
std::cout << "Processor #" << ppi->Number << " frequency: "
<< ppi->CurrentMhz << " MHz" << std::endl;
ppi++;
}
}
else
{
std::cout << "CallNtPowerInformation failed. Status: " << status << std::endl;
}
delete []pBuffer;
system("pause");
return status;
}
Resources
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|