c語(yǔ)言怎么獲取硬件信息
c語(yǔ)言怎么獲取硬件信息
對(duì)于程序員來(lái)講,使用C語(yǔ)言再正常不過(guò)了,那么,你們知道C語(yǔ)音應(yīng)該怎么獲取它的硬件信息呢?下面是學(xué)習(xí)啦小編帶來(lái)的關(guān)于c語(yǔ)言怎么獲取硬件信息的內(nèi)容,歡迎閱讀!
c語(yǔ)言怎么獲取硬件信息?
下面是C語(yǔ)言獲取硬件信息的代碼,可能比較長(zhǎng),請(qǐng)網(wǎng)友們細(xì)心查看
這個(gè)需要相關(guān)的庫(kù)以及API。
給你一個(gè)獲取cpu信息的函數(shù):
DWORD MyCPUSpeed()
{
BSTR bstrMyCpuName=NULL;
BSTR bstrMyPropName = NULL;
VARIANT pVal;
char szText[256];
int nCpuNum=0;
DWORD dwCpuSpeed=0;
IWbemClassObject *pCpuInst=NULL;
IWbemQualifierSet* pQualSet = NULL;
bstrMyPropName = SysAllocString(L"CurrentClockSpeed");
if(bstrMyPropName == NULL)
{
return dwCpuSpeed;
}
while(1)
{
memset(szText,0,sizeof(szText));
sprintf(szText,"Win32_Processor.DeviceID=\"CPU%d\"", nCpuNum);
bstrMyCpuName = _bstr_t(szText);
if(bstrMyCpuName == NULL)
{
break;
}
if(pSvc->GetObject(bstrMyCpuName, 0L, NULL, &pCpuInst, NULL) != S_OK)
{
break;
}
if(pCpuInst->Get(bstrMyPropName, 0L, &pVal, NULL, NULL) == S_OK)
{
nCpuNum++;
dwCpuSpeed += pVal.lVal;
}
VariantClear(&pVal);
SysFreeString(bstrMyCpuName);
bstrMyCpuName = NULL;
}
if(bstrMyPropName != NULL)
{
SysFreeString(bstrMyPropName);
bstrMyPropName = NULL;
}
if(bstrMyCpuName != NULL)
{
SysFreeString(bstrMyCpuName);
bstrMyCpuName = NULL;
}
memset(szText,0,sizeof(szText));
sprintf(szText, "CPU個(gè)數(shù): %d, CPU頻率: %ld Mhz", nCpuNum, dwCpuSpeed);
cout<<"------------------------"<
return dwCpuSpeed;
}
以上就是C語(yǔ)音怎么查看硬件信息的代碼了