I need to get the total physical memory of a system using Delphi 2007. Using GlobalMemoryStatus on a system with 4GB or greater seems to give me errors. In Delphi 2007 GlobalMemoryStatusEx does not exist so I added the function call to my program manually. It returns the memory on my Windows 7 x64 correctly (8GB) but on a Vista x32 system it still returns an incorrect value (should be 4GB on this system but returns 2.9GB). Any Idea what I may be doing wrong? And will the GlobalMemoryStatusEx work on older operating systems?
type
DWORDLONG = UInt64;
PMemoryStatusEx = ^TMemoryStatusEx;
TMemoryStatusEx = packed record
dwLength: DWORD;
dwMemoryLoad: DWORD;
ullTotalPhys: DWORDLONG;
ullAvailPhys: DWORDLONG;
ullTotalPageFile: DWORDLONG;
ullAvailPageFile: DWORDLONG;
ullTotalVirtual: DWORDLONG;
ullAvailVirtual: DWORDLONG;
ullAvailExtendedVirtual: DWORDLONG;
end;
function GlobalMemoryStatusEx(var lpBuffer: TMemoryStatusEx): BOOL; stdcall; external kernel32;
function getmemorysize:word;
var
memory: TMemoryStatusEx;
begin
FillChar(memory, SizeOf(memory), 0);
memory.dwLength := SizeOf(memory);
GlobalMemoryStatusEx(memory);
result:=memory.ullTotalPhys div (1024*1024);
end;