• 大小: 13.33MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-25
  • 语言: 其他
  • 标签: Intel  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\n“ 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!\n“ message);
return 1;
}
else
{
printf(“%s is checked unEnabled!\n“ message);
return 0;
}
}

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

sprintf_s(buf “time: %02d:%02d:%02d\n“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!\n“);
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!\n“);
return ;
}
fclose(fp);
}

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

评论

共有 条评论