獲取CPU信息的問題

wangyangcheng 2004-01-13 05:13:46
有不有哪位大哥談談獲取CPU的信息﹐包括廠商﹑型號﹑主頻的方法?

我找了一些資料﹐大致看出有如下方法﹕
1.利用PDH.dll﹐但好像只能在WinNT上實現﹐我需要在98/NT上都可實現。

2.如上面兄弟所說的用SYSTEM_INFO Si;這樣的方法來獲得的信息好像很有限.

3.用QueryPerformanceFrequency()這樣一些API獲取的值來計算。
我這里在codeguru上找了一段例子﹕
AUDITDLLEXIM long _stdcall GetProcessorClockSpeed(ULARGE_INTEGER &Hz)
{
unsigned __int64 start, stop;
unsigned __int64 nCtr, nFreq, nCtrStop;

QueryPerformanceFrequency((LARGE_INTEGER *)&nFreq);

__asm // inline assembly code block
{
_emit 0x0F
_emit 0x31
mov DWORD PTR start, eax
mov DWORD PTR [start+4], edx
}

QueryPerformanceCounter((LARGE_INTEGER *)&nCtrStop);

nCtrStop += nFreq;
do
QueryPerformanceCounter((LARGE_INTEGER *)&nCtr);
while (nCtr < nCtrStop);

__asm // inline assembly code block
{
_emit 0x0F
_emit 0x31
mov DWORD PTR stop, eax
mov DWORD PTR [stop+4], edx
}

Hz.QuadPart = (stop-start); // populate the 64bit part of the pointer
if ( Hz.QuadPart > 0 )
return 1;
else
return 0;
} // EOF GetProcessorClockSpeed()

但好像通不過。




請各高手指點一下﹐多謝﹗
...全文
756 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
nkwesley 2004-02-02
  • 打赏
  • 举报
回复
学习,关注
yintongshun 2004-01-30
  • 打赏
  • 举报
回复
http://www.hermes.com.cn/software/2000.08.28.htm

在www.tom.com上,用户名:mycsdn2003密码111111,Look
wangyangcheng 2004-01-27
  • 打赏
  • 举报
回复
shootingstars(有容乃大,无欲则刚) :please give me more details?
shootingstars 2004-01-26
  • 打赏
  • 举报
回复
cpuid指令并非所有CPU都支持。
myfoxprox 2004-01-26
  • 打赏
  • 举报
回复
我自己建了个检测INTEL CPU的DLL代码(我是用在VFP中加密用,呵呵...),修改一下就可以用了,你自己看一下有没有用:

#include "stdafx.h"
#include "atlstr.h"

extern "C" __declspec(dllexport) void getIntelCPUID(char *CPU_Type,char *CPU_ID)
{
unsigned long s1,s2;
unsigned char vendor_id[]="------------";//CPU提供商ID
CString str1,str2,str3;
// 以下为获得CPU ID的汇编语言指令
_asm // 得到CPU提供商信息
{
xor eax,eax // 将eax清0
cpuid // 获取CPUID的指令
mov dword ptr vendor_id,ebx
mov dword ptr vendor_id[+4],edx
mov dword ptr vendor_id[+8],ecx
}
str1.Format("%s",vendor_id);

_asm // 得到CPU ID的高32位
{
mov eax,01h
xor edx,edx
cpuid
mov s2,eax
}
str2.Format("%08X-",s2);

_asm // 得到CPU ID的低64位
{
mov eax,03h
xor ecx,ecx
xor edx,edx
cpuid
mov s1,edx
mov s2,ecx
}
str3.Format("%08X-%08X\n",s1,s2);

str2=str2+str3;
strcpy(CPU_Type,str1);
strcpy(CPU_ID,str2);
return;
}
wangyangcheng 2004-01-25
  • 打赏
  • 举报
回复
但我主要是想自已用API來實現。
而且運行在Win98上面。
danielzhu 2004-01-20
  • 打赏
  • 举报
回复
up
zhangcrony 2004-01-20
  • 打赏
  • 举报
回复
樓上方法正點﹗
shootingstars 2004-01-15
  • 打赏
  • 举报
回复
Supports Microsoft® Windows™ From:
Windows™ 95 / 95 OSR2 / 95 OSR2.5
Windows™ 98 / 98 SE
Windows™ Millennium
Windows™ NT 3.51
Windows™ NT 4.0 Workstation / Server [Including SP1 to SP6a]
Windows™ 2000 Workstation / Server / Advanced Server / Datacenter Server (Including SP1 to SP3)
Windows™ XP Personal / Professional [Including SP1]
Windows™ .NET Web Server / Standard Server / Enterprise Server

Supports Processors From:
Intel / AMD / Cyrix / Rise / UMC / IDT / Transmeta / NexGen / National Semiconductor

See Camel.txt for processor listings... E.g. Pentium III "Coppermine" or Athlon XP 1800+ (Thoroughbred Core).
Detects Hardware Features:
Processor hardware
Single Processors
Dual Processors
Multiple Processors
HyperThreading Technology
Serial Number [if enabled]
On-Chip APIC Hardware
Hard-Coded Chip Names
L1 Cache Size
L2 Cache Size
L3 Cache Size
CPU Clock Speed [of each processor]
Thermal Monitioring Support
ACPI Support
On-Chip PowerManagement [SpeedStep, etc.]

Multimedia Instruction Sets
MMX
MMX+
Streaming SIMD Extensions
Streaming SIMD Extensions [Floating Point]
Streaming SIMD Extensions [MMX]
Streaming SIMD Extensions 2
3DNow!
3DNow!+

General Instruction Sets
Floating Point Unit [FPU]
Time Stamp Counter [TSC]
Conditional Move [CMOV]
Memory Type Range Registers [MTRR]


http://www.codeproject.com/system/camel.asp
nava 2004-01-14
  • 打赏
  • 举报
回复
http://www.codeproject.com/csharp/wmi.asp

2,643

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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