Solved

How do I get the system resources and memory available?

Posted on 2000-02-27
3
149 Views
Last Modified: 2010-04-04
How do I get the system resources and memory available?
I want to get this information for using in my aboutbox.

                           Thank you
                           Lekhaew
0
Comment
Question by:lekhaew
3 Comments
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2563030
maybe this one?

var
  Mstat1 : TMemoryStatus;
{
  PMemoryStatus = ^TMemoryStatus;
  _MEMORYSTATUS = record
    dwLength: DWORD;
    dwMemoryLoad: DWORD;
    dwTotalPhys: DWORD;
    dwAvailPhys: DWORD;
    dwTotalPageFile: DWORD;
    dwAvailPageFile: DWORD;
    dwTotalVirtual: DWORD;
    dwAvailVirtual: DWORD;
  end;
}
begin
  FillChar( Mstat1, SizeOf( _MemoryStatus ), 0 );
  Mstat1.dwLength := SizeOf( _MemoryStatus );
  GlobalMemoryStatus( Mstat1 );
  showmessage( 'Phys. available: ' + IntToStr(Mstat1.dwAvailPhys));
end.
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 2563149
hi
the following shows you the system/user and gdi resources
Regards Barry


unit Thunker;

interface

const
  SYSres    = 0;
  USERres   = 2;
  GDIres    = 1;

function GetSystemResources(Res: Word): Word;
function UserPercentage : Integer;
function SystemPercentage : Integer;
function GDIPercentage : Integer;
procedure DisplayFreeResources;


implementation

uses Windows,SysUtils,Dialogs;

function ThunkLoadLibrary(LibraryName: PChar): THandle; stdcall; external kernel32 index 35;
procedure ThunkFreeLibrary(HInstance: THandle); stdcall; external kernel32 index 36;
function ThunkGetProcAddress(Hinstance: THandle; ProcName: PChar): Pointer; stdcall; external kernel32 index 37;
procedure Thunk; cdecl; external kernel32 name 'QT_Thunk';

{$StackFrames On}

var
  Th : THandle = 0;
  P: Pointer = nil;

function GetSystemResources(Res: Word): Word;
var
  Ar : array[0..$40] of Word;
begin
  Ar[0] := Th; //get major error without this ?
  Th := ThunkLoadLibrary('user.exe');
  if Th < 32 then
    raise Exception.Create('Error loading User.exe');
   ThunkFreeLibrary(Th);
  P := ThunkGetProcAddress(Th,'GetFreeSystemResources');
  if P = nil then
    raise Exception.Create('GetSystemResources function not found');
   asm
    push Res
    mov edx, P
    call Thunk
    mov Result, ax
  end;
end;

function UserPercentage : Integer;
 begin
  Result := GetSystemResources(USERres);
 end;

function SystemPercentage : Integer;
 begin
  Result := GetSystemResources(SYSres);
 end;

function GDIPercentage : Integer;
 begin
  Result := GetSystemResources(GDIres);
 end;

Procedure DisplayFreeResources;
begin
showmessage(
'SYSTEM : '+inttostr(SystemPercentage)+'%'+#13#10+
'USER : '+inttostr(UserPercentage)+'%'+#13#10+
'GDI : '+inttostr(GDIPercentage)+'%');
end;

end.



example program would include:

uses Thunker;

procedure TForm1.Button1Click(Sender: TObject);
begin
DisplayFreeResources;
end;
0
 

Author Comment

by:lekhaew
ID: 2571970
Thanks.
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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

13 Experts available now in Live!

Get 1:1 Help Now