====== Displaying Memory Size ====== When deploying an application, it may be necessary to determine whether the computer has enough memory. The Windows API function [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatus.asp|GlobalMemoryStatus]] returns this information, in a structure called MEMORYSTATUS. === Defining the MEMORYSTATUS Structure === Before calling this function, it is necessary to create this structure. To accomplish this, OpenInsight contains a window, called DEFINE_STRUCT. To run this window, navigate to the OpenInsight Executables section of the Repository Outline and locate the DEFINE_STRUCT window, as shown below: {{define_struct.gif?570x420}} Then press Shift-Double Click to run the Structure Designer. Create a new structure called MEMORYSTATUS, and populate it with eight unsigned long variables (the structure [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatus.asp|GlobalMemoryStatus()]] populates), as shown below: {{memorystatusstructure.gif?372x353}} The name of the structure is not critical, but for documentation and consistency it should match the structure name expected by the function. === The Code === Below is the code for calling [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatus.asp|GlobalMemoryStatus]]. To test, paste this code in the [[click_event|CLICK event]] of a button. declare function Get_Property, Blank_Struct declare subroutine GlobalMemoryStatus declare subroutine Parse_Struct gMemoryStatus = Blank_Struct("MEMORYSTATUS") GlobalMemoryStatus(gMemoryStatus) Parse_Struct(gMemoryStatus, "MEMORYSTATUS", length, memoryload, totalphys, availphys, totalpagefile, availpagefile, total_virtual, avail_virtual) call msg ( @window, ' Total physical memory ': totalphys / 1024 : 'KB, Available page file ': availpagefile / 1024: 'KB') [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatus.asp|GlobalMemoryStatus]] can be declared as a subroutine because the return value is ignored. Note how the variable gMemoryStatus is allocated memory (32 bytes) required by the MEMORYSTATUS structure, using the [[blank_struct|Blank_Struct()]] function. Then [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatus.asp|GlobalMemoryStatus]] is called, filling in the gMemoryStatus variable. Finally, the [[parse_struct|Parse_Struct]] subroutine populates the individual variables (length, memoryload, etc.) from the gMemoryStatus structure. === The Windows API Declaration === The code above will not run until the declaration for [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatus.asp|GlobalMemoryStatus]] has been added. To add the declaration, do the following: * Log out of the application. * Log into the SYSPROG application. * Add a row, (call it DLL_APICALLS_KERNEL32), with the first line as KERNEL32 and containing the declarations as shown below. Note that the structure parameter is passed as LPCHAR, a pointer to a character string. Since the function does not return a value, its return parameter is VOID. KERNEL32 VOID STDCALL GlobalMemoryStatus(LPCHAR) //...other KERNEL32 functions, if necessary * Save the row. * Run [[declare_fcns|Declare_FCNS]] at the System Editor Exec Line to create the declaration header, as shown below: RUN DECLARE_FCNS 'DLL_APICALLS_KERNEL32' * Exit the editor. * Log out of SYSPROG. * Log into your application. * Run the window. A message, displaying the total physical memory and available page file size, displays.