Mega Code Archive

 
Categories / Delphi / System
 

How to get memory values from Windows API

Title: How to get memory values from Windows API Question: I was about to create my own About dialog as the windows it self produces it... And there was the Memory available to Windows value... Answer: Here is the answer... This is a function that provides the memory values of physical memory, Virutal Memory, PageFile memory (available and free)... unit ugWinMemory; (* unit by Uros Gaber; eMail: uros.gaber@powercom-si.com *) interface // set the types of memory to get type TwmType = (wmAvailable, wmFree, wmVAvailable, wmVFree, wmPAvailable, wmPFree); (* wmAvailable = physical memory total wmFree = physical memory free wmVAvailable = virtual memory total wmVFree = virtual memory free wmPAvailable = PageFile memory total wmPFree = PageFile memory free *) function GetWindowsMemory(typ: TwmType): string; implementation function GetWindowsMemory(typ: TwmType): string; var memstatus: _MEMORYSTATUS; str_tmp: string; mem_stat: cardinal; begin GlobalMemoryStatus(memstatus); if typ=wmAvailable then mem_stat:=memstatus.dwTotalPhys; if typ=wmFree then mem_stat:=memstatus.dwAvailPhys; if typ=wmVAvailable then mem_stat:=memstatus.dwTotalVirtual; if typ=wmVFree then mem_stat:=memstatus.dwAvailVirtual; if typ=wmPAvailable then mem_stat:=memstatus.dwTotalPageFile; if typ=wmPFree then mem_stat:=memstatus.dwAvailPageFile; mem_stat:=mem_stat div 1024; GetWindowsMemory:=FloatToStrF(mem_stat, ffNumber, 18, 0)+' KB'; end; end.