然后在 VB 里面添加一个模块,添加如下代码:Private Declare Function GetCPUCount Lib "cpu.dll" () As Long Private Declare Function GetCPUFrequency Lib "cpu.dll" () As Long Private Declare Sub GetCPUString Lib "cpu.dll" (ByRef ch17rtn As Byte) Private Declare Sub GetCPUStdVendor Lib "cpu.dll" (ByRef ch48rtn As Byte)Public Function GetCPUFullDescription() As String On Error GoTo ErrProc: Dim strCPUString As String Dim strCPUStdVendor As String Dim ch17rtn(17) As Byte Dim ch48rtn(48) As Byte Dim i As Long GetCPUStdVendor ch17rtn(0) GetCPUString ch48rtn(0) For i = 0 To 17 strCPUStdVendor = strCPUStdVendor & Chr(ch17rtn(i)) Next For i = 0 To 48 strCPUString = strCPUString & Chr(ch48rtn(i)) Next strCPUStdVendor = Trim(Replace(strCPUStdVendor, Chr(0), " ")) strCPUString = Trim(Replace(strCPUString, Chr(0), " ")) If Len(strCPUString) < 10 Then strCPUString = strCPUStdVendor & " CPU" End If GetCPUFullDescription = GetCPUCount & " * " & strCPUString & " @ " & GetCPUFrequency & " MHz" Exit Function ErrProc: Debug.Print Err.Description End FunctionPublic Function GetShortCPUName() As String On Error GoTo ErrProc: Dim strCPUString As String Dim strCPUStdVendor As String Dim ch17rtn(17) As Byte Dim ch48rtn(48) As Byte Dim i As Long GetCPUStdVendor ch17rtn(0) GetCPUString ch48rtn(0) For i = 0 To 17 strCPUStdVendor = strCPUStdVendor & Chr(ch17rtn(i)) Next For i = 0 To 48 strCPUString = strCPUString & Chr(ch48rtn(i)) Next strCPUStdVendor = Trim(Replace(strCPUStdVendor, Chr(0), " ")) strCPUString = Trim(Replace(strCPUString, Chr(0), " ")) If Len(strCPUString) < 10 Then strCPUString = strCPUStdVendor & " CPU" End If GetShortCPUName = strCPUString Exit Function ErrProc: Debug.Print Err.Description End Function
详细说明: 文件包含一个dll文件VC源码+vb示例程序
dll文件需要VC编译 〕http://www.xingworld.net/show.html?root=1&branch=6&leaf=36&id=2519
{
union {
char CPUVendorString[13];
struct {
unsigned int dw00b;
unsigned int dw00c;
unsigned int dw00d;
char ch0;
} dws;
} CPUVendorData; CPUVendorData.dws.ch0 = '\0'; _asm {
xor eax, eax
cpuid
mov CPUVendorData.dws.dw00b, ebx
mov CPUVendorData.dws.dw00d, ecx
mov CPUVendorData.dws.dw00c, edx
}
strcpy((char *)szVendor, CPUVendorData.CPUVendorString);
}int __stdcall GetCPUCount()
{
SYSTEM_INFO info;
info.dwNumberOfProcessors = 0;
GetSystemInfo (&info);
return info.dwNumberOfProcessors;
}int __stdcall GetCPUFrequency()
{
LARGE_INTEGER CurrTicks, TicksCount;
__int64 iStartCounter, iStopCounter; DWORD dwOldProcessP = GetPriorityClass(GetCurrentProcess());
DWORD dwOldThreadP = GetThreadPriority(GetCurrentThread()); SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); QueryPerformanceFrequency(&TicksCount);
QueryPerformanceCounter(&CurrTicks); TicksCount.QuadPart /= 16;
TicksCount.QuadPart += CurrTicks.QuadPart; __asm rdtsc
__asm mov DWORD PTR iStartCounter, EAX
__asm mov DWORD PTR (iStartCounter+4), EDX while(CurrTicks.QuadPart<TicksCount.QuadPart)
QueryPerformanceCounter(&CurrTicks); __asm rdtsc
__asm mov DWORD PTR iStopCounter, EAX
__asm mov DWORD PTR (iStopCounter + 4), EDX SetThreadPriority(GetCurrentThread(), dwOldThreadP);
SetPriorityClass(GetCurrentProcess(), dwOldProcessP); return (int)((iStopCounter-iStartCounter)/62500);
}void __stdcall GetCPUString(char * szCPUName)
{
union {
char CPUNameString[48];
struct {
unsigned int dw02a;
unsigned int dw02b;
unsigned int dw02c;
unsigned int dw02d;
unsigned int dw03a;
unsigned int dw03b;
unsigned int dw03c;
unsigned int dw03d;
unsigned int dw04a;
unsigned int dw04b;
unsigned int dw04c;
unsigned int dw04d;
} dws;
} CPUNameData;
_asm {
xor eax, eax
mov eax, 80000002H
cpuid
mov CPUNameData.dws.dw02a, eax
mov CPUNameData.dws.dw02b, ebx
mov CPUNameData.dws.dw02c, ecx
mov CPUNameData.dws.dw02d, edx
xor eax, eax
mov eax, 80000003H
cpuid
mov CPUNameData.dws.dw03a, eax
mov CPUNameData.dws.dw03b, ebx
mov CPUNameData.dws.dw03c, ecx
mov CPUNameData.dws.dw03d, edx
xor eax, eax
mov eax, 80000004H
cpuid
mov CPUNameData.dws.dw04a, eax
mov CPUNameData.dws.dw04b, ebx
mov CPUNameData.dws.dw04c, ecx
mov CPUNameData.dws.dw04d, edx
}
strcpy((char *)szCPUName, CPUNameData.CPUNameString);
}把上面的文件编译成 dll,比如 cpu.dll
Private Declare Function GetCPUFrequency Lib "cpu.dll" () As Long
Private Declare Sub GetCPUString Lib "cpu.dll" (ByRef ch17rtn As Byte)
Private Declare Sub GetCPUStdVendor Lib "cpu.dll" (ByRef ch48rtn As Byte)Public Function GetCPUFullDescription() As String
On Error GoTo ErrProc:
Dim strCPUString As String
Dim strCPUStdVendor As String
Dim ch17rtn(17) As Byte
Dim ch48rtn(48) As Byte
Dim i As Long
GetCPUStdVendor ch17rtn(0)
GetCPUString ch48rtn(0)
For i = 0 To 17
strCPUStdVendor = strCPUStdVendor & Chr(ch17rtn(i))
Next
For i = 0 To 48
strCPUString = strCPUString & Chr(ch48rtn(i))
Next
strCPUStdVendor = Trim(Replace(strCPUStdVendor, Chr(0), " "))
strCPUString = Trim(Replace(strCPUString, Chr(0), " "))
If Len(strCPUString) < 10 Then
strCPUString = strCPUStdVendor & " CPU"
End If
GetCPUFullDescription = GetCPUCount & " * " & strCPUString & " @ " & GetCPUFrequency & " MHz"
Exit Function
ErrProc:
Debug.Print Err.Description
End FunctionPublic Function GetShortCPUName() As String
On Error GoTo ErrProc:
Dim strCPUString As String
Dim strCPUStdVendor As String
Dim ch17rtn(17) As Byte
Dim ch48rtn(48) As Byte
Dim i As Long
GetCPUStdVendor ch17rtn(0)
GetCPUString ch48rtn(0)
For i = 0 To 17
strCPUStdVendor = strCPUStdVendor & Chr(ch17rtn(i))
Next
For i = 0 To 48
strCPUString = strCPUString & Chr(ch48rtn(i))
Next
strCPUStdVendor = Trim(Replace(strCPUStdVendor, Chr(0), " "))
strCPUString = Trim(Replace(strCPUString, Chr(0), " "))
If Len(strCPUString) < 10 Then
strCPUString = strCPUStdVendor & " CPU"
End If
GetShortCPUName = strCPUString
Exit Function
ErrProc:
Debug.Print Err.Description
End Function