|
现在nvida官网下载SDK包
#include "stdafx.h"
#include <Windows.h>
#include "R450-developer/nvapi.h"
#pragma comment(lib,"R450-developer/x86/nvapi.lib")
DWORD __stdcall xs(LPVOID);
int _tmain(int argc, _TCHAR* argv[])
{
CreateThread(NULL,NULL,xs,NULL,NULL,NULL);
system("pause");
return 0;
}
DWORD __stdcall xs(LPVOID){
while(TRUE){
NvAPI_Status ret = NVAPI_OK;
NvU32 physicalGpuCount;
ret = NvAPI_Initialize();
if(ret != NVAPI_OK)
{
printf("NvAPI_Initialize() failed = 0x%x", ret);
return 1; // Initialization failed
}
NvPhysicalGpuHandle hPhysicalGpu[NVAPI_MAX_PHYSICAL_GPUS];
for (NvU32 PhysicalGpuIndex = 0; PhysicalGpuIndex < NVAPI_MAX_PHYSICAL_GPUS; PhysicalGpuIndex++)
{
hPhysicalGpu[PhysicalGpuIndex]=0;
}
ret = NvAPI_EnumPhysicalGPUs(hPhysicalGpu, &physicalGpuCount);
if(ret != NVAPI_OK)
{
printf("Cannot enumerate GPUs in the system...\n");
getchar();
exit(1);
}
NV_GPU_THERMAL_SETTINGS currentTemp;//获取温度的数据结构
currentTemp.version = NV_GPU_THERMAL_SETTINGS_VER;//一定要设置,不然调用获取温度函数时候会出错
for(NvU32 GpuIndex = 0; GpuIndex < physicalGpuCount; GpuIndex++)
{
ret = NvAPI_GPU_GetThermalSettings(hPhysicalGpu[GpuIndex], NVAPI_THERMAL_TARGET_ALL,¤tTemp);//获取温度
if(ret == NVAPI_OK)
{
system("CLS");
printf("current temperature=%d\n",currentTemp.sensor[0].currentTemp);
}
}
NvAPI_ShortString name;
NvAPI_GPU_GetFullName(hPhysicalGpu[0],name);//第一个显卡是[0],第二个显卡是[1]
printf("%s\n",name);
Sleep(1000);
}
}
|
|