首页
社区
课程
招聘
[求助]谁会用CallNtPowerInformation取cpu的主频?
发表于: 2009-9-1 17:57 8325

[求助]谁会用CallNtPowerInformation取cpu的主频?

2009-9-1 17:57
8325
在网上查到资料,说这个函数可以取cpu的主频,我试了下,什么都取不到

以下是我的源码,我用dev-c++编译的,引用了libPowrprof.a:

#include <cstdlib>
#include <iostream>
#include <windows.h> 
#ifndef   _HEADERFILENAME_H_   
#define   _HEADERFILENAME_H_   
#ifdef   __cplusplus   
extern   "C"   {   
#endif   
#include <Powrprof.h> 
#ifdef   __cplusplus   
}   
#endif   
#endif   //   _HEADERFILENAME_H_   
 
 
#include <WinDef.h> 

using namespace std;
typedef struct _PROCESSOR_POWER_INFORMATION {  
        ULONG Number;  
        ULONG MaxMhz;  
        ULONG CurrentMhz;  
        ULONG MhzLimit;  
        ULONG MaxIdleState;  
        ULONG CurrentIdleState; 
} PROCESSOR_POWER_INFORMATION,  *PPROCESSOR_POWER_INFORMATION; 

int main(int argc, char *argv[])


{
    
    NTSTATUS Processor_information; 
    PROCESSOR_POWER_INFORMATION p; 


    Processor_information=CallNtPowerInformation(ProcessorInformation, NULL, 0,&p, sizeof(p)); 
    if (Processor_information==STATUS_SUCCESS){
       printf("s \n");}
       else
       {printf("f \n");}
   
    printf("Number: \n", p.Number); 
    printf("maxhz: \n", p.MaxMhz);
    printf("CurrentMhz: \n", p.CurrentMhz);
    printf("MhzLimit: \n", p.MhzLimit);
    printf("MaxIdleState: \n", p.MaxIdleState);
    printf("CurrentIdleState: \n", p.CurrentIdleState);
    system("PAUSE");
    return EXIT_SUCCESS;
}


在vs 2005里面也试了,引用了Powrprof.lib,编译无错误,也什么都取不到

#include "stdafx.h"
#include <windows.h> 
#ifdef  __cplusplus  
extern  "C"  {  
#endif  
   #include <Powrprof.h>
#ifdef  __cplusplus  
}  
#endif  
#include <WinDef.h> 
 

typedef struct _PROCESSOR_POWER_INFORMATION {  ULONG Number;  ULONG MaxMhz;  ULONG CurrentMhz;  ULONG MhzLimit;  ULONG MaxIdleState;  ULONG CurrentIdleState; 
} PROCESSOR_POWER_INFORMATION,  *PPROCESSOR_POWER_INFORMATION; 

int _tmain(int argc, _TCHAR* argv[])
{


    PROCESSOR_POWER_INFORMATION p; 


    CallNtPowerInformation(ProcessorInformation, NULL, 0,&p, sizeof(p)); 


    printf("maxhz: \n", p.MaxMhz); 

    system("PAUSE"); 

    return 0;
}

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 251
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
我的机子上返回
STATUS_BUFFER_TOO_SMALL (0xC0000023)
一查
The lpInBuffer parameter must be NULL; otherwise the function returns ERROR_INVALID_PARAMETER.

The lpOutputBuffer buffer receives one PROCESSOR_POWER_INFORMATION structure for each processor that is installed on the system. Use the GetSystemInfo function to retrieve the number of processors.

简单来说就是有N个CPU 就要分配 N*sizeof(PROCESSOR_POWER_INFORMATION)大小的Buffer

另外楼主还有个低级错误,格式化字符串没写对,难道是cout用得太习惯了
2009-9-1 20:18
0
雪    币: 280
活跃值: (58)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
3
原来还要按cpu数分配buffer,问题解决了,谢谢啊
2009-9-1 22:24
0
游客
登录 | 注册 方可回帖
返回
//