Solved

How to GetFreeSystemResources in Delphi3 ?

Posted on 1998-08-27
13
500 Views
Last Modified: 2011-10-03
in delphi 1 there was a WinAPI-function available called GetFreeSystemResources. is there any WinAPI 32- function for delphi 3 to get the percentage of used/free system resource?

or any other possibility?

tia, Black Death.
0
Comment
Question by:BlackDeath
  • 7
  • 6
13 Comments
 
LVL 1

Author Comment

by:BlackDeath
ID: 1337897
Edited text of question
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1337898
Edited text of question
0
 
LVL 5

Expert Comment

by:inter
ID: 1337899
Hi,
The basic function is GlobalMemoryStatus, seek it from win32 help...If not enough just ask...
Regards, Igor
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 1

Author Comment

by:BlackDeath
ID: 1337900
Hoi, Igor!

i already use GlobalMemoryStatus for my project system information object. this is not what i need.

problem is:
GlobalMemoryStatus only provides information on memory status.

with GetFreeSystemResources you could get info on
-system resources (GFSR_SYSTEMRESOURCES) {= memory status}
-gdi resources    (GFSR_GDIRESOURCES)
-user resources   (GFSR_USERRESOURCES)

have you got something for these?

regs,
Black Death
0
 
LVL 5

Expert Comment

by:inter
ID: 1337901
Hi,
I have NT and browse through the KERNEL32, GDI32 and USER32 DLL's upon our conversation but could not find that kind of specific function in either of then rather than GetSystemInfo in kernel32. Did you see such 32 bit program that gives these information. Because on my win nt even ShellAbout gives only memory status...
Regards, Igor (there is another way, we may make thunking with 16 bit KERNEL DLL and you can call your funciton, however in that case it gives a virtual information amoung 16 bit processes which is not through in 32 bit subsystem...)
Regards, Igor
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1337902
igor -

resource meter (95), for example, provides you with information on these 3 different resource usage values. i dunno if it is available on nt, but i guess so. on 95, it is rsrcmtr.exe, and it is a 32bit-app...

.which i've browsed just now and found that it's using rsrc32.dll which exports
_MyGetFreeSystemResources32@4
thk_ThunkData32
and imports
KERNEL32.dll - ThunkConnect32

so, i guess your guess is what's to be guessed. (argh)

are you capable of implementing a thunking layer?

regs,

Black Death.
0
 
LVL 5

Expert Comment

by:inter
ID: 1337903
Hi,
There is a way for win32 on win95 but i am sorry for NT... It is called flat thunking and 4 undocumented functions exported from Kernel32 are used...Interested?
Regarsd, Igor
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1337904
mais oui, mon ami.

Black Death.
0
 
LVL 5

Expert Comment

by:inter
ID: 1337905
Hi, again,
The following is exactly what you want I think (if we are luckey, you did not even write single line of code). Any way make the following a seperate unit and call your GetFreeSystemResources with either 0,1, or 2

//***********************
// CODE STARTS
unit FreeRes;

{ Get free system resources in Windows 95.
  For reasons unknown outside of Microsoft, the Win32 API
  does not define the GetFreeSystemResources function.
  The only way to get this information is to call a 16-bit
  function in USER.EXE. You can try messing around with thunking,
  but there's an easier way in Windows 95. (I don't know how
  to do this in NT, though.)

  This information comes from "Windows 95 System Programming Secrets"
  by Matt Pietrek.

  This unit provides the GetFreeSystemResources function
  for Windows 95. See the Windows 3.1 API documentation
  to learn more about this function.

  Copyright © 1996 Tempest Software

  You may use this software as part of an application program
  without fee or royalty. Use this software at your own risk.
  As free software, it is offered without guarantee.
}

interface

const
  Gfsr_SystemResources = 0;
  Gfsr_GdiResources = 1;
  Gfsr_UserResources = 2;

function GetFreeSystemResources(SysResource: Word): Word;

implementation

uses SysUtils, Windows;

{ Undocumented Kernel32 calls. }
function LoadLibrary16(LibraryName: PChar): THandle; stdcall; external kernel32 index 35;
procedure FreeLibrary16(HInstance: THandle); stdcall; external kernel32 index 36;
function GetProcAddress16(Hinstance: THandle; ProcName: PChar): Pointer; stdcall; external kernel32 index 37;
procedure QT_Thunk; cdecl; external kernel32 name 'QT_Thunk';

{ Use global variables, so QT_Thunk does not trash them. }
var
  hInst16: THandle;
  GFSR: Pointer;

{ QT_Thunk needs a stack frame. }
{$StackFrames On}

{ Thunking call to 16-bit USER.EXE. The ThunkTrash argument
  allocates space on the stack for QT_Thunk. }
function GetFreeSystemResources(SysResource: Word): Word;
var
  ThunkTrash: array[0..$20] of Word;
begin
  { Prevent the optimizer from getting rid of ThunkTrash. }
  ThunkTrash[0] := hInst16;

  hInst16 := LoadLibrary16('user.exe');
  if hInst16 < 32 then
    raise Exception.Create('Cannot load USER.EXE');

  { Decrement the usage count. This doesn't really free the
    library, since USER.EXE is always loaded. }
  FreeLibrary16(hInst16);

  { Get the function pointer for the 16-bit function in USER.EXE. }
  GFSR := GetProcAddress16(hInst16, 'GetFreeSystemResources');
  if GFSR = nil then
    raise Exception.Create('Cannot get address of GetFreeSystemResources');

  { Thunk down to USER.EXE. }
  asm
    push SysResource  { push arguments }
    mov edx, GFSR     { load 16-bit procedure pointer }
    call QT_Thunk     { call thunk }
    mov Result, ax    { save the result }
  end;
end;

end.
// CODE ENDS
//***********************
Regards, Igor


0
 
LVL 5

Expert Comment

by:inter
ID: 1337906
Sorry,
I did not remember where I have learnt the Qthunking. Strangely, that comes up just what we want when I dig in to my code repository. So, I did not intentionally delay the solution,
excuse me,
Igor
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1337907
igor - it works.

please post an answer so i can award you.

thanxalot,

Black Death.
0
 
LVL 5

Accepted Solution

by:
inter earned 30 total points
ID: 1337908
I am glad that it works,
Cheers, Igor; - )
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1337909
me, too! thanxagain&bye,
Black.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question