It seems you are not initializing the structure and you're not checking the return code. Here's a compilable project which should work:
program Project1;
{$APPTYPE CONSOLE}
uses
Windows,
Classes,
SysUtils;
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;
procedure Main;
var
MemStatus: TMemoryStatusEx;
begin
// initialize the structure
FillChar(MemStatus, SizeOf(MemStatus), 0);
MemStatus.dwLength := SizeOf(MemStatus);
// check return code for errors
Win32Check(GlobalMemoryStatusEx(MemStatus));
Writeln(Format('dwLength: %d', [MemStatus.dwLength]));
Writeln(Format('dwMemoryLoad: %d', [MemStatus.dwMemoryLoad]));
Writeln(Format('ullTotalPhys: %d', [MemStatus.ullTotalPhys]));
Writeln(Format('ullAvailPhys: %d', [MemStatus.ullAvailPhys]));
Writeln(Format('ullTotalPageFile: %d', [MemStatus.ullTotalPageFile]));
Writeln(Format('ullAvailPageFile: %d', [MemStatus.ullAvailPageFile]));
Writeln(Format('ullTotalVirtual: %d', [MemStatus.ullTotalVirtual]));
Writeln(Format('ullAvailVirtual: %d', [MemStatus.ullAvailVirtual]));
Writeln(Format('ullAvailExtendedVirtual: %d', [MemStatus.ullAvailExtendedVirtual]));
end;
begin
try
Main;
except
on E: Exception do
begin
ExitCode := 1;
Writeln(Format('[%s] %s', [E.ClassName, E.Message]));
end;
end;
end.