有没有检测系统cpu、内存等是多少的函数?Help me!Thanks!

Judy7987 2003-08-20 09:13:12
请问有没有人用过什么函数检测系统的CPU及内存等硬件?谢谢!
...全文
55 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
bm1408 2003-08-25
  • 打赏
  • 举报
回复
利用API函数了!
Judy7987 2003-08-25
  • 打赏
  • 举报
回复
解决了,直接从注册表里读就可以了。呵呵。

谢谢大家!!!
紫郢剑侠 2003-08-22
  • 打赏
  • 举报
回复
学习....
Judy7987 2003-08-22
  • 打赏
  • 举报
回复
还是不大明白:用Time1的出了 Lasting Time: 804586872。

又有:CPU主频速率(Hz) = RDTSC读出的周期数 / 自CPU上电以来的秒数

这么说 CPU主频速率(Hz) = 804586872 / ?

不知道是不是除以1?
louifox 2003-08-22
  • 打赏
  • 举报
回复
http://www.csdn.net/Develop/article/15%5C15701.shtm
Judy7987 2003-08-22
  • 打赏
  • 举报
回复
完蛋了,还要用汇编,有没有封装好的库或函数什么的?
louifox 2003-08-22
  • 打赏
  • 举报
回复
如何检测CPU的主频
作者:罗云彬·发布日期:2000-7-21·阅读次数:2029


--------------------------------------------------------------------------------
【在这里下载本文的源代码】

概述:

说到检测CPU的速度,一般是测试在单位时间内运算的指令条数,但用这种方法有太大的局限性,由于受到很多因素的影响,准确度比较低,特别是在Windows环境下,你不知道在你的程序外别的程序占用了多少的时间片。其实,在586及以上档次处理器中,已经有了一条专用的指令来测试主频,那就是 RDTSC指令,意思是读取时间标记计数器(Read Time-Stamp Counter),Time-stamp counter 是处理器内部的一个64位的MSR (model specific register),它每个时钟增加一个记数。在处理器复位的时候,初始值为0,RDTSC 指令把 TSC的值低32位装入EAX中,高32位装入EDX中。如果CPU的主频是200MHz,那么在一秒钟内,TSC的值增加 200,000,000 次。所以在计算的时候,把两次的TSC差值除以两次的时间差值就是CPU的主频。
程序的结构如下: 初始化的时候设置一个定时器,定时时间为1秒,然后在定时器消息中利用 RDTSC 取得 TSC计数,再和上次保留的值相减,然后除以时间差即可。

源程序:

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Programmed by 罗云彬, bigluo@telekbird.com.cn
; Website: http://asm.yeah.net
; LuoYunBin's Win32 ASM page (罗云彬的编程乐园)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 版本信息
; CPU 频率 - 利用586指令 rdtsc 计算CPU的频率
; V1.0 ------ 2000年6月21日
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

.586
.model flat, stdcall
option casemap :none ; case sensitive

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 数据
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

include windows.inc
include user32.inc
include kernel32.inc
include comctl32.inc
include comdlg32.inc

includelib user32.lib
includelib kernel32.lib
includelib comctl32.lib
includelib comdlg32.lib

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ 数据
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

DLG_MAIN equ 1000
ID_SPEED equ 1001

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

.data?

dwTickCount dd ?
dwTSC dd ?,?
hInstance dd ?
szBuffer db 256 dup (?)

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 子程序声明
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain PROTO :DWORD,:DWORD,:DWORD,:DWORD

.data

szSpeed db "你的CPU主频为 %d MHz",0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

.code

include Win.asm

;********************************************************************
_ProcDlgMain proc uses ebx edi esi, \
hWnd:DWORD,wMsg:DWORD,wParam:DWORD,lParam:DWORD
local @stPoint:POINT
local @hWindow

mov eax,wMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
invoke KillTimer,hWnd,1
.elseif eax == WM_INITDIALOG
invoke _CenterWindow,hWnd
invoke GetTickCount ;TSC 初始值
mov dwTickCount,eax

rdtsc
mov dwTSC,eax
mov dwTSC+4,edx
invoke SetTimer,hWnd,1,1000,NULL
.elseif eax == WM_TIMER
invoke GetTickCount
push eax
sub eax,dwTickCount
pop dwTickCount
push eax

rdtsc
push edx
push eax
sub eax,dwTSC
sbb edx,dwTSC+4
pop dwTSC
pop dwTSC+4

mov ecx,1000000
div ecx ;除以1Mhz=1000000hz
.if edx >= 500000h ;四舍五入
inc eax
.endif
mov ecx,1000
mul ecx ;1秒=1000毫秒
pop ecx ;pop出经过的毫秒数
div ecx

invoke wsprintf,offset szBuffer,offset szSpeed,eax
invoke SendDlgItemMessage,hWnd,ID_SPEED,\
WM_SETTEXT,0,offset szBuffer
.else
;********************************************************************
; 注意:对话框的消息处理后,要返回 TRUE,对没有处理的消息
; 要返回 FALSE
;********************************************************************
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret

_ProcDlgMain endp
;********************************************************************
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,0
invoke ExitProcess,NULL

end start



Judy7987 2003-08-22
  • 打赏
  • 举报
回复
这条指令怎么用?能详细一点吗?谢谢!
louifox 2003-08-22
  • 打赏
  • 举报
回复
586以上的CPU有一条指令RDTSC可以做到。
CPU主频速率(Hz) = RDTSC读出的周期数 / 自CPU上电以来的秒数

Judy7987 2003-08-22
  • 打赏
  • 举报
回复
有没有人知道用什么办法可以知道cpu是多少GHz???????Thanks!Help me !
Judy7987 2003-08-22
  • 打赏
  • 举报
回复
有检测cpu是多少Hz的吗?
louifox 2003-08-22
  • 打赏
  • 举报
回复
还不明白?
用2个TIMER,计算这期间的RDTSC读出的周期数,再除以这段时间就可以了。
sandrowjw 2003-08-20
  • 打赏
  • 举报
回复
都在一起的,但是windows下面的信息不太准确。
Judy7987 2003-08-20
  • 打赏
  • 举报
回复
CPU解决了?可是内存呢?怎么取?Help me!!!!Thanks!
Judy7987 2003-08-20
  • 打赏
  • 举报
回复
没看到内存的呢?
Judy7987 2003-08-20
  • 打赏
  • 举报
回复
不好意思,刚才刷新不对,没看见。我看看哈,谢谢!
yzb1000 2003-08-20
  • 打赏
  • 举报
回复
The SYSTEM_INFO structure contains information about the current computer system. This includes the architecture and type of the processor, the number of processors in the system, the page size, and other such information.

typedef struct _SYSTEM_INFO {
union {
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO;
Members
dwOemId
An obsolete member that is retained for compatibility with Windows NT 3.5 and earlier. New applications should use the wProcessorArchitecture branch of the union.
Windows 95/98/Me: The system always sets this member to zero, the value defined for PROCESSOR_ARCHITECTURE_INTEL.

wProcessorArchitecture
Specifies the system's processor architecture. This value can be one of the following values:
PROCESSOR_ARCHITECTURE_UNKNOWN
PROCESSOR_ARCHITECTURE_INTEL
Windows NT 3.51: PROCESSOR_ARCHITECTURE_MIPS
Windows NT 4.0 and earlier: PROCESSOR_ARCHITECTURE_ALPHA
Windows NT 4.0 and earlier: PROCESSOR_ARCHITECTURE_PPC
64-bit Windows: PROCESSOR_ARCHITECTURE_IA64
64-bit Windows: PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
64-bit Windows: PROCESSOR_ARCHITECTURE_AMD64

wReserved
Reserved for future use.
dwPageSize
Specifies the page size and the granularity of page protection and commitment. This is the page size used by the VirtualAlloc function.
lpMinimumApplicationAddress
Pointer to the lowest memory address accessible to applications and dynamic-link libraries (DLLs).
lpMaximumApplicationAddress
Pointer to the highest memory address accessible to applications and DLLs.
dwActiveProcessorMask
Specifies a mask representing the set of processors configured into the system. Bit 0 is processor 0; bit 31 is processor 31.
dwNumberOfProcessors
Specifies the number of processors in the system.
dwProcessorType
An obsolete member that is retained for compatibility with Windows NT 3.5 and earlier. Use the wProcessorArchitecture, wProcessorLevel, and wProcessorRevision members to determine the type of processor.
Windows 95/98/Me: Specifies the type of processor in the system. This member is one of the following values:

PROCESSOR_INTEL_386
PROCESSOR_INTEL_486
PROCESSOR_INTEL_PENTIUM

dwAllocationGranularity
Specifies the granularity with which virtual memory is allocated. For example, a VirtualAlloc request to allocate 1 byte will reserve an address space of dwAllocationGranularity bytes. This value was hard coded as 64K in the past, but other hardware architectures may require different values.
wProcessorLevel
Windows NT/2000/XP: Specifies the system's architecture-dependent processor level.
If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_INTEL, wProcessorLevel can be one of the following values. Value Meaning
3 Intel 80386
4 Intel 80486
5 Intel Pentium
6 Intel Pentium Pro or Pentium II



If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_IA64, wProcessorLevel is set to 1.

If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_MIPS, wProcessorLevel is of the form 00xx, where xx is an 8-bit implementation number (bits 8-15 of the PRId register). The member can be the following value. Value Meaning
0004 MIPS R4000



If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_ALPHA, wProcessorLevel is of the form xxxx, where xxxx is a 16-bit processor version number (the low-order 16 bits of a version number from the firmware). The member can be one of the following values. Value Meaning
21064 Alpha 21064
21066 Alpha 21066
21164 Alpha 21164



If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_PPC, wProcessorLevel is of the form xxxx, where xxxx is a 16-bit processor version number (the high-order 16 bits of the Processor Version Register). The member can be one of the following values. Value Meaning
1 PPC 601
3 PPC 603
4 PPC 604
6 PPC 603+
9 PPC 604+
20 PPC 620



wProcessorRevision
Windows NT/2000/XP: Specifies an architecture-dependent processor revision. The following table shows how the revision value is assembled for each type of processor architecture. Processor Value
Intel 80386 or 80486 A value of the form xxyz.
If xx is equal to 0xFF, y - 0xA is the model number, and z is the stepping identifier. For example, an Intel 80486-D0 system returns 0xFFD0.

If xx is not equal to 0xFF, xx + 'A' is the stepping letter and yz is the minor stepping.

Intel Pentium, Cyrix, or NextGen 586 A value of the form xxyy, where xx is the model number and yy is the stepping. Display this value of 0x0201 as follows:
Model xx, Stepping yy

MIPS A value of the form 00xx, where xx is the 8-bit revision number of the processor (the low-order 8 bits of the PRId register).
ALPHA A value of the form xxyy, where xxyy is the low-order 16 bits of the processor revision number from the firmware. Display this value as follows:
Model A+xx, Pass yy

PPC A value of the form xxyy, where xxyy is the low-order 16 bits of the processor version register. Display this value as follows:
xx.yy

Judy7987 2003-08-20
  • 打赏
  • 举报
回复
是什么呀?说三。
yzb1000 2003-08-20
  • 打赏
  • 举报
回复
Getting Hardware Information
The following example uses the GetSystemInfo function to obtain hardware information such as the OEM identifier, processor type, page size, and so on. The example displays the information in a window's client area.

SYSTEM_INFO siSysInfo; // struct. for hardware information
int aTabs[1] = {260}; // tab stop for TabbedTextOut

TCHAR tchBuffer[BUFFER]; // buffer for expanded string
int nSize; // size of string

// Display the "hardware information" header.

nSize = sprintf(tchBuffer,
"Hardware information:");
TextOut(hdc, 15, 20, tchBuffer, nSize);

// Copy the hardware information to the SYSTEM_INFO structure.

GetSystemInfo(&siSysInfo);

// Display the contents of the SYSTEM_INFO structure.

nSize = sprintf(tchBuffer,
"OEM ID: %u\tNumber of Processors: %u",
siSysInfo.dwOemId,
siSysInfo.dwNumberOfProcessors);
TabbedTextOut(hdc, 25, 40, tchBuffer,
nSize, 1, aTabs, 25);

nSize = sprintf(tchBuffer,
"Page size: %u\tProcessor Type: %u",
siSysInfo.dwPageSize,
siSysInfo.dwProcessorType);
TabbedTextOut(hdc, 25, 60, tchBuffer,
nSize, 1, aTabs, 25);

nSize = sprintf(tchBuffer,
"Minimum app address: %lx\tMaximum app address: %lx",
siSysInfo.lpMinimumApplicationAddress,
siSysInfo.lpMaximumApplicationAddress);
TabbedTextOut(hdc, 25, 80, tchBuffer,
nSize, 1, aTabs, 25);

nSize = sprintf(tchBuffer,
"Active processor mask: %u",
siSysInfo.dwActiveProcessorMask);
TextOut(hdc, 25, 100, tchBuffer, nSize);
The following example uses the GetSystemMetrics function to determine whether a mouse is installed and whether the mouse buttons are swapped. The example also uses the SystemParametersInfo function to retrieve the mouse threshold and speed. It displays the information in a message box.

TCHAR tchBuffer[BUFFER]; // buffer for expanded string
int nSize; // size of string

BOOL fResult; // system shutdown flag

int aMouseInfo[3]; // array for mouse information

// Is there a mouse?

fResult = GetSystemMetrics(SM_MOUSEPRESENT);

if (fResult == 0)
{
// Indicate if there is no mouse.

nSize = sprintf(tchBuffer, "No mouse installed.");
}
else
{
// If there is a mouse, determine whether its buttons are swapped.

fResult = GetSystemMetrics(SM_SWAPBUTTON);

if (fResult == 0)
{
nSize = sprintf(tchBuffer, "Buttons not swapped.\r");
}
else
{
nSize = sprintf(tchBuffer, "Buttons swapped.\r");
}

// Get the mouse speed and the threshold values.

SystemParametersInfo(SPI_GETMOUSE, // get mouse information
NULL, // not used
&aMouseInfo, // holds mouse information
NULL); // not used

nSize += sprintf(tchBuffer + nSize,
"Speed: %d\r", aMouseInfo[2]);
sprintf(tchBuffer + nSize,
"Threshold (x,y): %d,%d",
aMouseInfo[0], aMouseInfo[1]);
}

// Display the mouse information.

MessageBox(NULL, tchBuffer, "Mouse information",
MB_ICONINFORMATION);
This next example uses SystemParametersInfo to double the mouse speed and update the MouseSpeed value in the WIN.INI file.

TCHAR tchBuffer[BUFFER]; // buffer for expanded string
int nSize; // size of string

int aMouseInfo[3]; // array for mouse information

// Get the current mouse speed.

SystemParametersInfo(SPI_GETMOUSE, // get mouse information
NULL, // not used
&aMouseInfo, // holds mouse information
NULL); // not used

// Double it.

aMouseInfo[2] = 2 * aMouseInfo[2];

// Change the mouse speed to the new value and update WIN.INI.

SystemParametersInfo(SPI_SETMOUSE, // set mouse information
NULL, // not used
aMouseInfo, // mouse information
SPIF_UPDATEINIFILE); // update win.ini
yzb1000 2003-08-20
  • 打赏
  • 举报
回复
当然有啊

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧