Solved

How to GetFreeSystemResources in Delphi3 ?

Posted on 1998-08-27
13
497 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
Comment Utility
Edited text of question
0
 
LVL 1

Author Comment

by:BlackDeath
Comment Utility
Edited text of question
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
Hi,
The basic function is GlobalMemoryStatus, seek it from win32 help...If not enough just ask...
Regards, Igor
0
 
LVL 1

Author Comment

by:BlackDeath
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Expert Comment

by:inter
Comment Utility
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
Comment Utility
mais oui, mon ami.

Black Death.
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I am glad that it works,
Cheers, Igor; - )
0
 
LVL 1

Author Comment

by:BlackDeath
Comment Utility
me, too! thanxagain&bye,
Black.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now