Win2k fix: GetSystemTimes() is not available before WinXP with SP-1.

This commit is contained in:
LoRd_MuldeR 2011-10-29 22:26:39 +02:00
parent b1098f4177
commit a6ddde787e
2 changed files with 18 additions and 2 deletions

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 3 #define VER_LAMEXP_MINOR_LO 3
#define VER_LAMEXP_TYPE RC #define VER_LAMEXP_TYPE RC
#define VER_LAMEXP_PATCH 3 #define VER_LAMEXP_PATCH 3
#define VER_LAMEXP_BUILD 760 #define VER_LAMEXP_BUILD 762
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Tools versions // Tools versions

View File

@ -23,6 +23,9 @@
#include "Global.h" #include "Global.h"
#include <QDir> #include <QDir>
#include <QLibrary>
typedef BOOL (WINAPI *GetSystemTimesPtr)(LPFILETIME lpIdleTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Constructor & Destructor // Constructor & Destructor
@ -73,9 +76,22 @@ void CPUObserverThread::observe(void)
{ {
ULONGLONG sys[2], usr[2], idl[2]; ULONGLONG sys[2], usr[2], idl[2];
FILETIME sysTime, usrTime, idlTime; FILETIME sysTime, usrTime, idlTime;
QLibrary kernel32("kernel32.dll");
GetSystemTimesPtr getSystemTimes = NULL;
bool first = true; bool first = true;
double previous = -1.0; double previous = -1.0;
if(kernel32.load())
{
getSystemTimes = reinterpret_cast<GetSystemTimesPtr>(kernel32.resolve("GetSystemTimes"));
}
if(getSystemTimes == NULL)
{
qWarning("GetSystemTimes() ist not available on this system!");
return;
}
for(size_t i = 0; i < 2; i++) for(size_t i = 0; i < 2; i++)
{ {
sys[i] = 0; usr[i] = 0; idl[i] = 0; sys[i] = 0; usr[i] = 0; idl[i] = 0;
@ -83,7 +99,7 @@ void CPUObserverThread::observe(void)
while(!m_terminated) while(!m_terminated)
{ {
if(GetSystemTimes(&idlTime, &sysTime, &usrTime)) if(getSystemTimes(&idlTime, &sysTime, &usrTime))
{ {
sys[1] = sys[0]; sys[0] = filetime2ulonglong(&sysTime); sys[1] = sys[0]; sys[0] = filetime2ulonglong(&sysTime);
usr[1] = usr[0]; usr[0] = filetime2ulonglong(&usrTime); usr[1] = usr[0]; usr[0] = filetime2ulonglong(&usrTime);