[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

How to GetFreeSystemResources in Delphi3 ?

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
BlackDeath
Asked:
BlackDeath
  • 7
  • 6
1 Solution
 
BlackDeathAuthor Commented:
Edited text of question
0
 
BlackDeathAuthor Commented:
Edited text of question
0
 
interCommented:
Hi,
The basic function is GlobalMemoryStatus, seek it from win32 help...If not enough just ask...
Regards, Igor
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BlackDeathAuthor Commented:
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
 
interCommented:
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
 
BlackDeathAuthor Commented:
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
 
interCommented:
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
 
BlackDeathAuthor Commented:
mais oui, mon ami.

Black Death.
0
 
interCommented:
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
 
interCommented:
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
 
BlackDeathAuthor Commented:
igor - it works.

please post an answer so i can award you.

thanxalot,

Black Death.
0
 
interCommented:
I am glad that it works,
Cheers, Igor; - )
0
 
BlackDeathAuthor Commented:
me, too! thanxagain&bye,
Black.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now