 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Lapo Guidi Guest
|
Posted: Wed Oct 12, 2005 12:51 am Post subject: GetSystemTimes and Borland C++ Builder |
|
|
A great HI to all!
I have a problem calculating the CPU usage.
I readed the MSDN and I see that i need to use GetSystemTimes API to get
Idle time, Kernel time and User time to calculate it.
My problem is that this function is quite new so my BCB 6 haven't it in
winbase.h and, I suppose, in Kernel32.lib.
Somebody can help me to solve the problem?
Should I download the Platform SDK from Microsoft site?
Thanks for the answer.
Bye
Lapo
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Oct 12, 2005 2:37 am Post subject: Re: GetSystemTimes and Borland C++ Builder |
|
|
"Lapo Guidi" <lapoguidi (AT) inwind (DOT) it> wrote
| Quote: | My problem is that this function is quite new so my BCB 6
haven't it in winbase.h and, I suppose, in Kernel32.lib.
|
GetSystemTimes() is only available on XP SP1, 2003 Server, and Vista
(Longhorn). BCB6 was released years before any of them were released.
| Quote: | Somebody can help me to solve the problem?
|
Use GetModuleHandle() and GetProcAddress() to load the function dynamically
at runtime. For example:
typedef BOOL (__stdcall *LPFN_GST)(LPFILETIME, LPFILETIME, LPFILETIME);
LPFN_GST lpGetSystemTimes = (LPFN_GST)
GetProcAddress(GetModuleHandle("KERNEL32"), "GetSystemTimes");
if( lpGetSystemTimes )
{
FILETIME IdleTime, KernelTime, UserTime;
if( lpGetSystemTimes(&IdleTime, &KernelTime, &UserTime) )
{
// use IdleTime, KernelTime, UserTime as needed...
}
else
{
DWORD dwError = GetLastError();
// use dwError as needed...
}
}
| Quote: | Should I download the Platform SDK from Microsoft site?
|
No, because much of it is not usable with BCB as-is. Borland usually has to
make tweaks to the PSDK in order for it to work with Borland's compiler and
then release their own copy of it with the IDE.
Gambit
|
|
| Back to top |
|
 |
Lapo Guidi Guest
|
Posted: Wed Oct 12, 2005 11:23 pm Post subject: Re: GetSystemTimes and Borland C++ Builder |
|
|
Okay, I used the method you suggested me and it works fine.
But I would ask you another suggestion, if I can:
I readed that NT/2k/XP Task Manager uses NtQuerySystemInformation, but
Microsoft suggest to use the GetSystemTimes function.
Do you think I should use GetSystemTiimes as Microsoft suggest or should I
use the old NtQuerySystemInformation?
Thanks for your help and for your suggestion.
Lapo
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Oct 12, 2005 11:39 pm Post subject: Re: GetSystemTimes and Borland C++ Builder |
|
|
"Lapo Guidi" <lapoguidi (AT) inwind (DOT) it> wrote
| Quote: | I readed that NT/2k/XP Task Manager uses NtQuerySystemInformation,
but Microsoft suggest to use the GetSystemTimes function.Do you think I
should use GetSystemTiimes as Microsoft suggest or should I use the old
NtQuerySystemInformation?
|
As I already mentioned earlier, GetSystemTimes() is only available on the
most modern of OS versions (XP S1, 2003 Server, and Vista). That means when
GetSystemTimes() is not available on a particular machine, you will have to
fallback to using NtQuerySystemInformation().
Gambit
|
|
| Back to top |
|
 |
Lapo Guidi Guest
|
Posted: Thu Oct 13, 2005 12:07 am Post subject: Re: GetSystemTimes and Borland C++ Builder |
|
|
Well, I got the point.
Thanks
Lapo
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|