获取系统的CPU个数的vc代码
作者:cnfgg 日期:2009-11-13
如何获取系统的CPU个数的vc代码如下(调用ntdll.dll中的NtQuerySystemInformation函数):
复制内容到剪贴板
程序代码
程序代码#include <windows.h>
//一些预定义---
#define SystemBasicInformation 0
#define SystemPerformanceInformation 2
#define SystemTimeInformation 3
#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))
//存储系统基本信息的结构体
typedef struct
{
DWORD dwUnknown1;
ULONG uKeMaximumIncrement;
ULONG uPageSize;
ULONG uMmNumberOfPhysicalPages;
ULONG uMmLowestPhysicalPage;
ULONG uMmHighestPhysicalPage;
ULONG uAllocationGranularity;
PVOID pLowestUserAddress;
PVOID pMmHighestUserAddress;
ULONG uKeActiveProcessors;
BYTE bKeNumberProcessors;
BYTE bUnknown2;
WORD wUnknown3;
} SYSTEM_BASIC_INFORMATION;
//声明一个函数指针类型
typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);
PROCNTQSI NtQuerySystemInformation;
int GetCpuNum()
{
SYSTEM_BASIC_INFORMATION SysBaseInfo;
LONG status;
//获得ntdll.dll中NtQuerySystemInformation函数指针
NtQuerySystemInformation=(PROCNTQSI)GetProcAddress(
GetModuleHandleA("ntdll") , "NtQuerySystemInformation");
if (!NtQuerySystemInformation)
return 1;
//获取系统基本信息,这里要得到系统的CPU个数
status = NtQuerySystemInformation(SystemBasicInformation,&SysBaseInfo,sizeof(SysBaseInfo),NULL);
if (status != NO_ERROR)
return 1;
return SysBaseInfo.bKeNumberProcessors;
}
评论: 0 | 引用: 0 | 查看次数: -
发表评论
上一篇
下一篇

文章来自:
Tags:
相关日志: