c获取cpu频率
答案:1 悬赏:0 手机版
解决时间 2021-11-09 17:41
- 提问者网友:缘字诀
- 2021-11-09 13:51
c获取cpu频率
最佳答案
- 五星知识达人网友:渊鱼
- 2021-11-09 14:22
给你一个函数吧。
--------------
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个数: %d, CPU频率: %ld Mhz", nCpuNum, dwCpuSpeed);
cout<<"------------------------"< return dwCpuSpeed;
}
不行你再联系我。呵呵。
--------------
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个数: %d, CPU频率: %ld Mhz", nCpuNum, dwCpuSpeed);
cout<<"------------------------"<
}
不行你再联系我。呵呵。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯