读取cpu温度


支持Intel 核心温度读取,AMD的不行
资源截图
代码片段和文件信息
#include “stdafx.h“
#include “ReadCpuInfo.h“
#include 

ReadCpuInfo::ReadCpuInfo()
{
ReadCpuInfoInit(); 
strcpy_s(fileName “CpuInfoRecord.txt“);
}


ReadCpuInfo::~ReadCpuInfo()
{
ReadCpuInfoExit();
}

void ReadCpuInfo::ReadCpuTemp()
{
for (size_t i = 0; i < coreNumber; i++)
{
int mask =  0x01 << i;
SetProcessAffinityMask(GetCurrentProcess() mask);
DWORD eax ebx ecx edx;
Rdmsr(0x19c &eax &edx);
cpuTemp[i] = 100 - ((eax & 0x7f0000) >> 16);
}

}


void ReadCpuInfo::ReadCpuInfoInit()
{
if (true == CheckAndPrint(“Init DLL function“ InitializeOls()))
{
if (true == CheckAndPrint(“IsCpuid function“ IsCpuid()))
{
if (true == CheckAndPrint(“Ismsr function“ IsMsr()))
{
DWORD eax ebx ecx edx;
Rdmsr(0x1A2 &eax &edx);
Tjmax = (eax & 0xff0000) >> 16;
//printf(“%d
“ Tjmax);                          //show max temperature
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
coreNumber = sysInfo.dwNumberOfProcessors;
SetProcessAffinityMask(GetCurrentProcess() 1);    //init read cpu0 info;
}
}
}
}

void ReadCpuInfo::ReadCpuInfoExit()
{
DeinitializeOls();
}
int ReadCpuInfo::CheckAndPrint(char message[] BOOL flag)
{
if (flag)
{
printf(“%s is checked Enable!
“ message);
return 1;
}
else
{
printf(“%s is checked unEnabled!
“ message);
return 0;
}
}

void ReadCpuInfo::CpuTempDisplay()
{
for (size_t i = 0; i < coreNumber; i++)
{
char buf[1024] = ““;
#if (CONSOLE_PRINT)
printf(“Core #%d: %dC
“ i cpuTemp[i]);
#else
#endif
sprintf_s(buf “Core #%d: %dC
“ i cpuTemp[i]);
RecordCpuInfo(buf);
}
}
void ReadCpuInfo::SysTimeDisplay()
{
clearRecordFile();
SYSTEMTIME start; //windows.h中   
GetLocalTime(&start);//time.h的tm结构体一样的效果   
//printf(“%d
“ start.wHour);
#if (CONSOLE_PRINT)
printf(“date: %02d/%02d/%02d

start.wYear start.wMonth start.wDay);
printf(“time: %02d:%02d:%02d

start.wHour start.wMinute start.wSecond);
#else
#endif
char buf[1024] = ““;
sprintf_s(buf “date: %02d/%02d/%02d
“ start.wYear start.wMonth start.wDay);
RecordCpuInfo(buf);
memset(buf 0 sizeof(buf));

sprintf_s(buf “time: %02d:%02d:%02d
“start.wHour start.wMinute start.wSecond);
RecordCpuInfo(buf);


}

void ReadCpuInfo::RecordCpuInfo(char *buf)
{
FILE *fp;
fopen_s(&fpfileName “a+“);
if (fp == NULL)
{
printf(“file open error!
“);
return;
}
else
{
fwrite(buf strlen(buf) 1 fp);
}
fclose(fp);

}

void ReadCpuInfo:: clearRecordFile()
{
FILE *fp;
fopen_s(&fpfileName “w+“);
if (fp == NULL)
{
printf(“file open error!
“);
return ;
}
fclose(fp);
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-04-20 10:26  readPcInfo
     目录           0  2016-03-18 09:54  readPcInfoDebug
     文件          90  2016-04-20 09:43  readPcInfoDebugCpuInfoRecord.txt
     文件       65536  2016-03-08 15:36  readPcInfoDebug
eadPcInfo.exe
     文件      389912  2016-03-08 15:36  readPcInfoDebug
eadPcInfo.ilk
     文件     1256448  2016-03-08 15:36  readPcInfoDebug
eadPcInfo.pdb
     文件       65536  2009-05-24 11:34  readPcInfoDebugWinRing0.dll
     文件       14416  2008-07-26 22:30  readPcInfoDebugWinRing0.sys
     文件       57856  2009-05-27 21:59  readPcInfoDebugWinRing0x64.dll
     文件       14544  2008-07-26 22:30  readPcInfoDebugWinRing0x64.sys
     目录           0  2016-03-22 16:52  readPcInfoipch
     目录           0  2016-04-20 09:44  readPcInfoipch
eadpcinfo-28a6d5b0
     文件     3080192  2016-04-20 09:44  readPcInfoipch
eadpcinfo-28a6d5b0
eadpcinfo-b71dfa21.ipch
     目录           0  2016-03-18 09:54  readPcInfoipch
eadpcinfo-e29dfd5d
     文件     3080192  2016-03-08 15:36  readPcInfoipch
eadpcinfo-e29dfd5d
eadpcinfo-7740a867.ipch
     目录           0  2016-04-20 10:23  readPcInfo
eadPcInfo
     文件    32571392  2016-04-20 10:26  readPcInfo
eadPcInfo.sdf
     文件         976  2016-03-08 09:10  readPcInfo
eadPcInfo.sln
     文件       35840  2016-04-20 10:26  readPcInfo
eadPcInfo.v12.suo
     文件          90  2016-04-20 10:23  readPcInfo
eadPcInfoCpuInfoRecord.txt
     目录           0  2016-03-18 09:54  readPcInfo
eadPcInfoDebug
     文件        7122  2016-03-08 14:12  readPcInfo
eadPcInfoDebugCpuInfoWriteFile.obj
     文件       48271  2016-03-08 14:56  readPcInfo
eadPcInfoDebugReadCpuInfo.obj
     文件        1142  2016-03-08 15:36  readPcInfo
eadPcInfoDebug
eadPcInfo.log
     文件      164624  2016-03-08 14:56  readPcInfo
eadPcInfoDebug
eadPcInfo.obj
     文件     2424832  2016-03-08 14:11  readPcInfo
eadPcInfoDebug
eadPcInfo.pch
     目录           0  2016-03-18 09:54  readPcInfo
eadPcInfoDebug
eadPcInfo.tlog
     文件        3174  2016-03-08 14:56  readPcInfo
eadPcInfoDebug
eadPcInfo.tlogcl.command.1.tlog
     文件       43688  2016-03-08 15:36  readPcInfo
eadPcInfoDebug
eadPcInfo.tlogCL.read.1.tlog
     文件        4372  2016-03-08 14:56  readPcInfo
eadPcInfoDebug
eadPcInfo.tlogCL.write.1.tlog
     文件        1618  2016-03-08 15:36  readPcInfo
eadPcInfoDebug
eadPcInfo.tloglink.command.1.tlog
............此处省略42个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)