Temperature - System Info

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Promythyus Offline
Junior Member
Posts: 4
Joined: May 2012
Reputation: 0
Post: #11
Well, after examining http://msdn.microsoft.com/en-us/library/...85%29.aspx I have come up with the following code;
Code:
const int           bufSize = 4096;
    HANDLE              hChildStd_OUT_Rd = NULL,
                        hChildStd_OUT_Wr = NULL;
    SECURITY_ATTRIBUTES saAttr;
    TCHAR               win32cmd[] = TEXT("tempcmd /cpu");
    PROCESS_INFORMATION piProcInfo;
    STARTUPINFO         siStartInfo;
    DWORD               dwRead;
    CHAR                chBuf[bufSize];

    saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
    saAttr.bInheritHandle = TRUE;
    saAttr.lpSecurityDescriptor = NULL;

    CreatePipe(&hChildStd_OUT_Rd, &hChildStd_OUT_Wr, &saAttr, 0);
    SetHandleInformation(hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0);

    ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
    ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));

    siStartInfo.cb = sizeof(STARTUPINFO);
    siStartInfo.hStdOutput = hChildStd_OUT_Wr;
    siStartInfo.dwFlags |= STARTF_USESTDHANDLES;

    CreateProcess(NULL, win32cmd, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &siStartInfo, &piProcInfo);

    for(;;)
    {
        BOOL bSuccess = FALSE;
        bSuccess = ReadFile(hChildStd_OUT_Rd, chBuf, bufSize, &dwRead, NULL);
        if(!bSuccess || dwRead == 0)
            break;
    }

Not ready to be put into XBMC or anything but it gets the gist of it. Problem is, ReadFile() just hangs in ntdll.dll. Not having much skill in C++ I have no idea what I'm doing wrong, so I fear this is as far as I'll get.

Regarding DDDamian's code, that would make a great fallback if m_cpuTempCmd is empty, so that people with boards that expose temp via WMI don't have to do anything, but those with boards that don't like jhsrennie can set their own command.

As an aside, I noticed that the temperatures are only taken upon first entering the system info menu, unlike all the other stats that are updated every second or so whilst in the menu. Perhaps temperatures should be updated in the same way?

EDIT: I have this code in a #ifdef _WIN32 at line 364 in xbmc\utils\CPUInfo.cpp, btw.
(This post was last modified: 2012-05-06 17:28 by Promythyus.)
find quote
Post Reply