📄 cpuinfodlg.cpp
字号:
UINT CCpuinfoDlg::FindPhoenixBios( BYTE** ppBiosAddr )
{
UINT uOffset[3] = { 0x6577, 0x7196, 0x7550 };
BYTE szBiosPhoenix[8] = "Phoenix";//Phoenix
BYTE* pBiosAddr = * ppBiosAddr;
for(DWORD i = 0; i < sizePage/128; i++)
{
for(int j = 0; j < 128; j++)
{
if(pBiosAddr[0] == szBiosPhoenix[0]
&& pBiosAddr[1] == szBiosPhoenix[1]
&& pBiosAddr[2] == szBiosPhoenix[2]
&& pBiosAddr[3] == szBiosPhoenix[3]
&& pBiosAddr[4] == szBiosPhoenix[4]
&& pBiosAddr[5] == szBiosPhoenix[5]
&& pBiosAddr[6] == szBiosPhoenix[6])
{
return 7;
}
pBiosAddr ++;
}
}
/* UINT uOffset[3] = { 0x6577, 0x7196, 0x7550 };
for( UINT i = 0; i < 3; ++ i )
{
BYTE* pBiosAddr = * ppBiosAddr + uOffset[i];
BYTE szBiosData[128];
CopyMemory( szBiosData, pBiosAddr, 127 );
szBiosData[127] = 0;
int iLen = lstrlen( ( char* )szBiosData );
if( iLen > 0 && iLen < 128 )
{
// Example: Phoenix "NITELT0.86B.0044.P11.9910111055"
if( szBiosData[7] == '.' && szBiosData[11] == '.' )
{
BYTE* p = szBiosData;
while( * p )
{
if( * p < ' ' || * p >= 127 )
{
break;
}
++ p;
}
if( * p == 0 )
{
* ppBiosAddr = pBiosAddr;
return ( UINT )iLen;
}
}
}
}
*/
return 0;
}
//////////////////////////////////////////////////////////////////////////
void CCpuinfoDlg::MacAdpGet()
{
UINT uErrorCode = 0;
UCHAR szSystemInfo[1024] = {0};
IP_ADAPTER_INFO iai;
ULONG uSize = 0;
DWORD dwResult = GetAdaptersInfo( &iai, &uSize );
if( dwResult == ERROR_BUFFER_OVERFLOW )
{
IP_ADAPTER_INFO* piai = ( IP_ADAPTER_INFO* )HeapAlloc( GetProcessHeap( ), 0, uSize );
if( piai != NULL )
{
dwResult = GetAdaptersInfo( piai, &uSize );
if( ERROR_SUCCESS == dwResult )
{
IP_ADAPTER_INFO* piai2 = piai;
CopyMemory( szSystemInfo, piai2->Address, piai2->AddressLength );
}
else
{
uErrorCode = 0xF0000000U + dwResult;
}
VERIFY( HeapFree( GetProcessHeap( ), 0, piai ) );
}
else
{
return;
}
}
else
{
uErrorCode = 0xE0000000U + dwResult;
}
if( uErrorCode != 0U )
{
return;
}
strList.Format( "MAC Address: %02X%02X%02X%02X%02X%02X",
szSystemInfo[0],
szSystemInfo[1],
szSystemInfo[2],
szSystemInfo[3],
szSystemInfo[4],
szSystemInfo[5]);
m_list.AddString(strList);
}
//得到cpu的ID
void CCpuinfoDlg::CpuIDGet()
{
BOOL bException = FALSE;
BYTE szCpu[16] = { 0 };
UINT uCpuID = 0U;
char szCpuINC[128] = {0};
__try
{
_asm
{
mov eax, 0
cpuid
mov dword ptr szCpu[0], ebx
mov dword ptr szCpu[4], edx
mov dword ptr szCpu[8], ecx
mov eax, 1
cpuid
mov uCpuID, edx
}
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
bException = TRUE;
}
if( !bException )
{
strList.Format("CPU ID: %0X", uCpuID);
m_list.AddString(strList);
CopyMemory( szCpuINC, szCpu, strlen( ( char* )szCpu ) );
strList.Format("Grade of CPU: %s", szCpuINC);
m_list.AddString(strList);
}
}
//-----------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCPUInfo::CCPUInfo()
{
char OEMString[13];
int iEAXValue,iEBXValue,iECXValue,iEDXValue;
//获取CPU的品牌:
_asm
{
mov eax,0
cpuid
mov DWORD PTR OEMString,ebx
mov DWORD PTR OEMString+4,edx
mov DWORD PTR OEMString+8,ecx
mov BYTE PTR OEMString+12,0
}
Name=new char[15];
strcpy(Name, OEMString);
//更多CPU信息:
_asm
{
mov eax,1
cpuid
mov iEAXValue,eax
mov iEBXValue,ebx
mov iECXValue,ecx
mov iEDXValue,edx
}
MMX = bool(iEDXValue & 0x800000);
iFamily=(0xf00 & iEAXValue)>>8;
FPU = bool(iEDXValue & 0x1);
}
CCPUInfo::~CCPUInfo()
{
delete []Name;
}
DWORD CCPUInfo::GetSpeed()
{
int PriorityClass, Priority;
HANDLE hThread,hProcess;
hThread=GetCurrentThread();
hProcess=GetCurrentProcess();
PriorityClass = GetPriorityClass(hProcess);
Priority = GetThreadPriority(hThread);
SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(hThread,THREAD_PRIORITY_TIME_CRITICAL);
long lEAXValue,lEDXValue;
SleepEx(50,false);
_asm
{
xor eax,eax
rdtsc
mov lEAXValue,eax
mov lEDXValue,edx
}
if(SleepEx(500,false)==0)
{
_asm
{
xor eax,eax
rdtsc
sub eax,lEAXValue
sbb edx,lEDXValue
mov lEAXValue, eax
mov lEDXValue, edx
}
}
SetThreadPriority(hThread, Priority);
SetPriorityClass(hProcess, PriorityClass);
return lEAXValue/(1000.0*500);
}
bool CCPUInfo::withMMX()
{
return MMX;
}
int CCPUInfo::GetFamily()
{
return iFamily;
}
int CCPUInfo::GetName(char *name)
{
if(name==NULL) return -1;
strcpy(name, Name);
return 0;
}
int CCPUInfo::GetTypeName(char *type)
{
//EAX的8到11位表明是几86:
// 3 - 386
// 4 - i486
// 5 - Pentium
// 6 - Pentium Pro Pentium II
// 2 - Dual Processors
if(type==NULL) return -1;
switch(iFamily)
{
case 2: strcpy(type,"Dual Processors");break;
case 3: strcpy(type,"386");break;
case 4: strcpy(type,"486");break;
case 5: strcpy(type,"Pentium");break;
case 6: strcpy(type,"P2,celeron,Pentium Pro");break;
default: strcpy(type,"Unknown Type");
}
return 0;
}
bool CCPUInfo::hasFPU()
{
return FPU;
}
void CCpuinfoDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
CoUninitialize();
}
void CCpuinfoDlg::OnButton3()
{
GiveText( "------------------------- 所有WMI信息 -----------------------");
BSTR bstrInfoArray[] = {
L"Win32_BIOS",
L"Win32_1394Controller",
L"Win32_BaseBoard",
L"Win32_Battery",
L"Win32_Bus",
L"Win32_CacheMemory",
L"Win32_CDROMDrive",
L"Win32_CurrentProbe",
L"Win32_DesktopMonitor",
L"Win32_DeviceMemoryAddress",
L"Win32_DiskDrive",
L"Win32_DisplayConfiguration",
L"Win32_DisplayControllerConfiguration",
L"Win32_DMAChannel",
L"Win32_Fan",
L"Win32_FloppyController",
L"Win32_FloppyDrive",
L"Win32_HeatPipe",
L"Win32_IDEController",
L"Win32_InfraredDevice",
L"Win32_IRQResource",
L"Win32_Keyboard",
L"Win32_MemoryArray",
L"Win32_MemoryDevice",
L"Win32_MotherboardDevice",
L"Win32_NetworkAdapter",
L"Win32_NetworkAdapterConfiguration",
L"Win32_OnBoardDevicev",
L"Win32_ParallelPortv",
L"Win32_PCMCIAController",
L"Win32_PhysicalMemory",
L"Win32_PhysicalMemoryArray",
L"Win32_PnPEntity",
L"Win32_PointingDevice",
L"Win32_PortableBattery",
L"Win32_PortConnector",
L"Win32_PortResource",
L"Win32_POTSModem",
L"Win32_PowerManagementEvent",
L"Win32_Printer",
L"Win32_PrinterConfiguration",
L"Win32_PrintJob",
L"Win32_Processor",
L"Win32_Refrigeration",
L"Win32_SerialPort",
L"Win32_SerialPortConfiguration",
L"Win32_SMBIOSMemory",
L"Win32_SoundDevice",
L"Win32_SystemEnclosure",
L"Win32_SystemMemoryResource",
L"Win32_SystemSlot",
L"Win32_TapeDrive",
L"Win32_TemperatureProbe",
L"Win32_UninterruptiblePowerSupply",
L"Win32_USBController",
L"Win32_VideoConfiguration",
L"Win32_VideoController",
L"Win32_VoltageProbe",
NULL};
//Win32_NamedJobObjectProcess
//BSTR bstrInfoBIOS = (L"Select * from Win32_NamedJobObjectProcess");
BSTR bstrInfor = L"";
for(int i = 0; (i < 100) || bstrInfoArray[i] == NULL; i++)
{
if(bstrInfoArray[i] == NULL)
break;
CComBSTR bstrTemp = L"Select * from ";
bstrTemp.Append(bstrInfoArray[i]);
bstrInfor = bstrTemp;
wmigetsysteminformation(bstrInfor);
}
}
void CCpuinfoDlg::wmigetsysteminformation(BSTR bstrInfoKind)
{
IWbemLocator *pWbemLocator = NULL;
CString strTmp;
// CoGetClassObject(rclsid, dwClsContext, NULL, IID_IClassFactory, &pCF);
if(CoCreateInstance(CLSID_WbemAdministrativeLocator, NULL,
CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pWbemLocator) == S_OK)
{
IWbemServices *pWbemServices = NULL;
if(pWbemLocator->ConnectServer((BSTR)(L"root\\cimv2"), NULL, NULL, 0, NULL, 0, 0, &pWbemServices) == S_OK)
{
IEnumWbemClassObject *pEnumClassObject = NULL;
if(pWbemServices->ExecQuery((BSTR)(L"WQL"), bstrInfoKind, WBEM_FLAG_RETURN_IMMEDIATELY,NULL, &pEnumClassObject) == S_OK)
{
IWbemClassObject *pClassObject = NULL;
ULONG uCount = 1, uReturned;
if(pEnumClassObject->Reset() == S_OK)
{
int iEnumIdx = 0;
while(pEnumClassObject->Next(WBEM_INFINITE, uCount, &pClassObject, &uReturned) == S_OK)
{
char tmp[128] = {0};
itoa(iEnumIdx, tmp, 10);
strTmp.Format("------------------------ [%s] ------------------------", tmp);
m_list.AddString(strTmp);
SAFEARRAY *pvNames = NULL;
if(pClassObject->GetNames(NULL, WBEM_FLAG_ALWAYS |
WBEM_MASK_CONDITION_ORIGIN, NULL, &pvNames) == S_OK)
{
long vbl, vbu;
SafeArrayGetLBound(pvNames, 1, &vbl);
SafeArrayGetUBound(pvNames, 1, &vbu);
for(long idx=vbl; idx<=vbu; idx++)
{
long aidx = idx;
wchar_t *wsName = 0;
VARIANTARG vValue;
VariantInit(&vValue);
vValue.bstrVal = NULL;
SafeArrayGetElement(pvNames, &aidx, &wsName);
BSTR bs = SysAllocString(wsName);
HRESULT hRes = pClassObject->Get(bs, 0, &vValue, NULL, 0);
SysFreeString(bs);
if(hRes == S_OK)
{
CString s;
VARIANTARG v;
VariantInit(&v);
v.bstrVal = NULL;
v = *(VARIANTARG*)&vValue;
CString str = "NULL";
if(v.vt == 8)
str = v.bstrVal;
strList = " -- ";
strList += str;
strTmp = CString(wsName) ;
strTmp += strList;
m_list.AddString(strTmp);
}
VariantClear(&vValue);
SysFreeString(wsName);
}
}
if(pvNames)SafeArrayDestroy(pvNames);
iEnumIdx++;
}
}
if(pClassObject)pClassObject->Release();
}
if(pEnumClassObject)pEnumClassObject->Release();
}
if(pWbemServices)pWbemServices->Release();
}
if(pWbemLocator)pWbemLocator->Release();
}
void CCpuinfoDlg::OnButton2()
{
GiveText( "------------------------- wmi获得bios信息 -----------------------");
//通过wmi获得bios信息
BSTR bstrInfoBIOS = (L"Select * from Win32_BIOS");
wmigetsysteminformation(bstrInfoBIOS);
}
void CCpuinfoDlg::OnBnClickedButton5()
{
GiveText( "------------------------- WMI CPU 信息 -----------------------");
//Win32_Processor
BSTR bstrInfo = (L"Select * from Win32_Processor");
wmigetsysteminformation(bstrInfo);
}
void CCpuinfoDlg::OnBnClickedButton6()
{
GiveText( "------------------------- 网卡信息 -----------------------");
//通过wmi获得Netadapt信息
BSTR bstrInfo = (L"Select * from Win32_NetworkAdapter");
wmigetsysteminformation(bstrInfo);
}
void CCpuinfoDlg::OnBnClickedButton7()
{
GiveText( "------------------------- 网卡配置信息 -----------------------");
//Win32_NetworkAdapterConfiguration
BSTR bstrInfo = (L"Select * from Win32_NetworkAdapterConfiguration");
wmigetsysteminformation(bstrInfo);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -