Hi !I am trying to call GlobalMemoryStatusEx that has as parameter the structure: MEMORYSTATUSEX defined as:
typedef struct _MEMORYSTATUSEX {
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX,
*LPMEMORYSTATUSEX;
Could anybody tell write the corresponding TYPE definition to use it ?
I got this from previous posting where the <4GB Mem function was used. Ref:
http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/c8197e1d9cedd881852568e4004a0d11?OpenDocument&Highlight=0,GlobalMemoryStatus
Thanks
Francisco
Subject: MEMORYSTATUSEX type in Kernel32 GlobalMemoryStatusEx
Try this:
Type MemoryStatusEx
Length As Long
MemoryLoad As Long
TotalPhysLo As Long
TotalPhysHi As Long
AvailPhysLo As Long
AvailPhysHi As Long
TotalPageFileLo As Long
TotalPageFileHi As Long
AvailPageFileLo As Long
AvailPageFileHi As Long
TotalVirtualLo As Long
TotalVirtualHi As Long
AvailVirtualLo As Long
AvailVirtualHi As Long
AvailExtendedVirtualLo As Long
AvailExtendedVirtualHi As Long
End Type
Then TotalPhys = 2^32 * TotalPhysHi + TotalPhysLo.
And don’t forget to set MemoryStatusEx.Length to Len(MemoryStatusEx) before you call GlobalMemoryStatusEx (GlobalMemoryStatus didn’t have this requirement).
Subject: RE: MEMORYSTATUSEX type in Kernel32 GlobalMemoryStatusEx
I’ve been playing around with this in order to record the amount of memory installed on my servers in the NAB, so here’s the result.You can run this either as a scheduled or manual agent, and it even works on Linux. 
Option Public
Option Declare
%INCLUDE “lsconst”
Type MemoryStatusEx
Length As Long
MemoryLoad As Long
TotalPhysLo As Long
TotalPhysHi As Long
AvailPhysLo As Long
AvailPhysHi As Long
TotalPageFileLo As Long
TotalPageFileHi As Long
AvailPageFileLo As Long
AvailPageFileHi As Long
TotalVirtualLo As Long
TotalVirtualHi As Long
AvailVirtualLo As Long
AvailVirtualHi As Long
AvailExtendedVirtualLo As Long
AvailExtendedVirtualHi As Long
End Type
Declare Function GlobalMemoryStatusEx Lib “kernel32” (lpBuffer As MemoryStatusEx) As Long
Sub Initialize
'Either displays to screen or records to server doc
'the amount of RAM installed on this computer.
Dim s As New NotesSession
Dim i As Long
Dim mb As Double
If IsDefined ("WIN32") Then
mb = GetMemWindows
Elseif IsDefined ("LINUX") Then
mb = GetMemLinux
Else
Exit Sub
End If
If mb = 0 Then Exit Sub
i = Log (mb) / Log(2) - 4 ' Rounds to the nearest 'real' memory size
mb = Cint (mb / 2^i) * 2^i ' by only keeping the 5 most significant bits
If s.IsOnServer Then
Dim db As New NotesDatabase ("", "names")
Dim doc As NotesDocument
Set doc = db.GetView ("($ServersLookup)").GetDocumentByKey (s.UserName)
Do
If doc.HasItem ("ServerMemoryMB") Then If doc.ServerMemoryMB(0) = mb Then Exit Do
doc.ReplaceItemValue "ServerMemoryMB", mb
doc.Save False, False
Loop Until True
Else
Dim mul
Dim mem As String
mul = Evaluate ({@Explode ("Mo Go To Po")})
i = Cint (Log(mb) / Log(1024))
mem = mb / 2^(i*10) & " " & mul (i)
Messagebox "Your computer has " & mem & " MB of RAM.", MB_ICONINFORMATION, s.CurrentAgent.Name
End If
End Sub
Function GetMemWindows As Double
'Gets installed memory size in MB
Dim memStatusEx As MemoryStatusEx
Dim mem As Double
memStatusEx.Length = Len (memStatusEx)
If GlobalMemoryStatusEx (memStatusEx) Then
mem = Abs (memStatusEx.TotalPhysLo)
If memStatusEx.TotalPhysLo < 0 Then mem = mem + 2^31 ' There's no 64-bit unsigned integer in LS
mem = mem + Abs (memStatusEx.TotalPhysHi) * 2^32 ' so a few adjustements are required...
If memStatusEx.TotalPhysHi < 0 Then mem = mem + 2^63
GetMemWindows = mem / 2^20 ' From bytes to MB...
End If
End Function
Function GetMemLinux As Double
'Gets installed memory size in MB
Const mth = "MemTotal:"
Dim i As Long
Dim l As String
i = Freefile
Open "/proc/meminfo" For Input As #i
Line Input #i, l
Close #i
If Instr (l, mth) = 1 Then
l = Strright (l, mth)
GetMemLinux = Val(l) / 1024
End If
End Function