Solved

How to GetFreeSystemResources in Delphi3 ?

Posted on 1998-08-27
13
507 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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