GlobalMemoryStatus returns 0 on 64-bit operating system
Symptom
When deploying an application as 64-bit in PowerBuilder, calls to
the function GlobalMemoryStatus () will always return 0 for available
physical and virtual memory.
Environment
-
Any 64-bit Windows Operating System
-
PowerBuilder
Reproducing the Issue
Call the function GlobalMemoryStatus(), passing an appropriate
memory object, and read the values of memobject.ll_availphys and
memobject.ll_availvirtual. Both will be 0 on a 64-bit operating system
even when running the application in 32-bit.
Cause
The size of the structure passed to the API is 64-bits and this
data is not parsed correctly when stored in a 32-bit object’s
variables.
Solution
-
You can redefine the GlobalMemoryStatus local external
function and a new structure to pass to the function:1Subroutine GlobalMemoryStatus (ref os_memorystatusmemorystatus) Library "KERNEL32.DLL" alias for "GlobalMemoryStatusEx" -
Define a new structure to hold the data:
1234567891011typeos_memorystatus from structureunsignedlong ul_lengthunsignedlong ul_memoryloadlonglong ll_totalphyslonglong ll_availphyslonglong ll_totalpagefilelonglong ll_availpagefilelonglong ll_totalvirtuallonglong ll_availvirtuallonglong ll_AvailExtendedVirtualend type -
Make sure the memory object’s ul_length variable equals 64
before calling GlobalMemoryStatus():123os_memorystatussysmemsysmem.ul_length = 64GlobalMemoryStatus(sysmem)