• 大小: 6.16MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2023-09-25
  • 语言: 其他
  • 标签: MFC  VC2010  winring0  

资源简介

使用winring0监控CPU温度,网上的例子基本都要积分下载,没有积分怎么整,中文的真是没有一点共享精神,最后是在google找到的资源,结合网上的教程整出来了。可惜最低限制是1分,如果可以我一分也不要。

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “ReadCpuInfo.h“
#include 


ReadCpuInfo::ReadCpuInfo(void)
{
ReadCpuInfoInit();      //构造函数初始化dll
strcpy_s(fileName “CpuInfoRecord.txt“);
}


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

void ReadCpuInfo::ReadCpuTemp()      //主要函数
{
for (int i = 0; i < coreNumber; i++) //遍历CPU
{
int mask =  0x01 << i;         
SetProcessAffinityMask(GetCurrentProcess() mask);//设置当前使用线程(CPU)
DWORD eax ebx ecx edx;
Rdmsr(0x19c &eax &edx);    //读取温度寄存器(eax&0x7f0000可以获得温度数据)
cpuTemp[i] = Tjmax - ((eax & 0x7f0000) >> 16);//实际温度= Tjmax - 温度数据
}

}

void ReadCpuInfo::ReadCpuInfoInit()      //初始化
{
if (true == CheckAndPrint(“Init DLL function“ InitializeOls()))                   //dll的初始化
{
if (true == CheckAndPrint(“IsCpuid function“ IsCpuid()))                      //判断是否支持Cpuid
{
if (true == CheckAndPrint(“Ismsr function“ IsMsr()))                       //是否支持Rdmsr
{
DWORD eax ebx ecx edx;
Rdmsr(0x1A2 &eax &edx);   //读取寄存器
Tjmax = (eax & 0xff0000) >> 16; //获得Tjmax
//printf(“%d\n“ Tjmax);                          //show max temperature
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
coreNumber = sysInfo.dwNumberOfProcessors;  //获得线程数
SetProcessAffinityMask(GetCurrentProcess() 1);    //切换到第一个cpu;
}
}
}
}

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 (int 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)
{
#if INFO_IN_FILE
FILE *fp;
fopen_s(&fpfileName “a+“);
if (fp == NULL)
{
printf(“file open error!\n“);
return;
}
else
{
fwrite(buf strlen(buf) 1 fp);
}
fclose(fp);
#endif

}

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

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-09 21:13  ext\
     目录           0  2018-08-09 21:06  ext\winring0dllAndExe\
     目录           0  2018-08-09 21:10  ext\winring0dllAndExe\exe\
     目录           0  2018-08-09 20:57  ext\winring0dllAndExe\exe\x64Debug\
     文件     8251392  2018-08-09 20:53  ext\winring0dllAndExe\exe\x64Debug\WinRing0SampleCppX64.exe
     文件       68608  2018-08-09 20:51  ext\winring0dllAndExe\exe\x64Debug\WinRing0x64.dll
     文件       14544  2008-07-26 22:30  ext\winring0dllAndExe\exe\x64Debug\WinRing0x64.sys
     目录           0  2018-08-09 21:04  ext\winring0dllAndExe\exe\x64Release\
     文件     2217984  2018-08-09 20:58  ext\winring0dllAndExe\exe\x64Release\WinRing0SampleCppX64.exe
     文件       54272  2018-08-09 20:52  ext\winring0dllAndExe\exe\x64Release\WinRing0x64.dll
     文件       14544  2008-07-26 22:30  ext\winring0dllAndExe\exe\x64Release\WinRing0x64.sys
     目录           0  2018-08-09 21:11  ext\winring0dllAndExe\exe\x86Debug\
     文件       53248  2018-08-09 20:48  ext\winring0dllAndExe\exe\x86Debug\WinRing0.dll
     文件     5957120  2018-08-09 21:09  ext\winring0dllAndExe\exe\x86Debug\WinRing0SampleCpp.exe
     文件       14544  2008-07-26 22:30  ext\winring0dllAndExe\exe\x86Debug\WinRing0x64.sys
     目录           0  2018-08-09 21:09  ext\winring0dllAndExe\exe\x86Release\
     文件       46080  2018-08-09 20:50  ext\winring0dllAndExe\exe\x86Release\WinRing0.dll
     文件     1534464  2018-08-09 21:08  ext\winring0dllAndExe\exe\x86Release\WinRing0SampleCpp.exe
     文件       14544  2008-07-26 22:30  ext\winring0dllAndExe\exe\x86Release\WinRing0x64.sys
     目录           0  2018-08-09 20:53  ext\winring0dllAndExe\sys\
     文件       14416  2008-07-26 22:30  ext\winring0dllAndExe\sys\WinRing0.sys
     文件       14544  2008-07-26 22:30  ext\winring0dllAndExe\sys\WinRing0x64.sys
     目录           0  2018-08-09 21:04  ext\winring0dllAndExe\x64Debug\
     文件       14942  2018-08-09 20:51  ext\winring0dllAndExe\x64Debug\WinRing0.lib
     文件       68608  2018-08-09 20:51  ext\winring0dllAndExe\x64Debug\WinRing0x64.dll
     目录           0  2018-08-09 21:05  ext\winring0dllAndExe\x64Release\
     文件       54272  2018-08-09 20:52  ext\winring0dllAndExe\x64Release\WinRing0x64.dll
     文件       15120  2018-08-09 20:52  ext\winring0dllAndExe\x64Release\WinRing0x64.lib
     目录           0  2018-08-09 21:06  ext\winring0dllAndExe\x86Debug\
     文件       53248  2018-08-09 20:48  ext\winring0dllAndExe\x86Debug\WinRing0Debug.dll
     文件       15164  2018-08-09 20:48  ext\winring0dllAndExe\x86Debug\WinRing0Debug.lib
............此处省略118个文件信息

评论

共有 条评论