Microsoft KB Archive/306826

= How To Get and Set the Memory Settings with eVB =

Article ID: 306826

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft eMbedded Visual Basic 3.0

-



This article was previously published under Q306826



SUMMARY
This article demonstrates how to use an eMbedded Visual Basic (eVB) application to adjust the system memory division.



MORE INFORMATION
On Microsoft Windows CE devices, you can adjust the memory settings to allocate memory between object store (storage) and program memory. This adjustment is typically made in the system's Control Panel. The sample code to follow illustrates how you can use the SetSystemMemoryDivision function to programmatically set this boundary line.

Step-by-Step Example
 Start a new PocketPC project in eVB. Form1 is created by default. Add six labels, two text boxes, two command buttons, one horizontal scroll bar, and one shape control to Form1. Do not be concerned with the placement of these controls.  Paste the following code into Form1: Option Explicit Const SYSMEM_CHANGED = 0 Const SYSMEM_FAILED = 3

Declare Function GetLastError Lib &quot;coredll&quot; As Long

Declare Function GetSystemMemoryDivision Lib &quot;coredll&quot; _ (lpdwStorePages As Long, _    lpdwRamPages As Long, _     lpdwPageSize As Long) As Long

Declare Function SetSystemMemoryDivision Lib &quot;coredll&quot; _ (ByVal dwStorePages As Long) As Long

Dim lStorePages As Long Dim lPageSize As Long Dim lRamPages As Long Private Sub GetMemoryInfo Dim lRet As Long lRet = GetSystemMemoryDivision(lStorePages, lRamPages, lPageSize) If lRet > 0 Then SetUI Else MsgBox &quot;Call failed&quot; End If End Sub

Private Sub Command1_Click GetMemoryInfo End Sub

Private Sub Command2_Click Dim lRet As Long lRet = SetSystemMemoryDivision(lStorePages) If lRet = SYSMEM_FAILED Then MsgBox &quot;Failure....GetLastError returned: &quot; & GetLastError End If   GetMemoryInfo End Sub

Private Sub Form_OKClick App.End End Sub

Sub SetUI HScroll1.Max = lStorePages + lRamPages HScroll1.Value = lStorePages Label4.Caption = &quot;Total main memory: &quot; & _ FormatNumber(TurntoMB(lStorePages + lRamPages)) & &quot; MB&quot; Text1.Text = FormatNumber(TurntoMB(lStorePages), 2) & &quot; MB&quot; Text2.Text = FormatNumber(TurntoMB(lRamPages), 2) & &quot; MB&quot; Label5.Caption = Text1.Text Label6.Caption = Text2.Text End Sub

Public Function TurntoMB(lsize As Long) As Long TurntoMB = (lsize * lPageSize) / 1024 ^ 2 End Function

Public Function TurnToMem(lsize As Long) As Long TurnToMem = (lsize / lPageSize) * 1024 ^ 2 End Function

Private Sub HScroll1_Change Text1.Text = FormatNumber(TurntoMB(HScroll1.Value), 2) & &quot; MB&quot; Text2.Text = FormatNumber(TurntoMB(HScroll1.Max - _ HScroll1.Value), 2) & &quot; MB&quot; lStorePages = HScroll1.Value End Sub

Private Sub Form_Load Label1.Caption = &quot;Storage&quot; Label2.Caption = &quot;Program&quot; Label3.Caption = &quot;Allocated&quot; Label4.Caption = &quot;&quot; Label5.Caption = &quot;&quot; Label6.Caption = &quot;&quot; Text1.Text = &quot;&quot; Text2.Text = &quot;&quot; Form1.Caption = &quot;Memory Division&quot; Command1.Caption = &quot;Get Memory Info&quot; Command2.Caption = &quot;Set Memory Info&quot; HScroll1.Min = 0 HScroll1.Max = 8000 HScroll1.LargeChange = 100 HScroll1.SmallChange = 10 Label1.Move 120, 480, 735, 255 Label2.Move 2400, 480, 735, 255 Label3.Move 1320, 1680, 855, 255 Label4.Move 120, 120, 2895, 255 Label5.Move 240, 1680, 975, 255 Label6.Move 2280, 1680, 975, 255 Text1.Move 120, 840, 975, 255 Text2.Move 2400, 840, 975, 255 Command1.Move 120, 2520, 2055, 375 Command2.Move 120, 3000, 2055, 375 HScroll1.Move 120, 1200, 3255, 255 Shape1.Move 120, 1560, 3255, 495

GetMemoryInfo End Sub  Ensure that the remote device is being targeted, and run the application. Scroll the horizontal scroll bar, and click Set Memory Info to change the memory settings.

IMPORTANT: A PocketPC runs a memory division check at least once every 5 seconds and whenever the Task Manager starts an application. As a part of this check, the memory division is set to equal parts if it is determined that free memory in one division is 5 times larger than the free memory in the other.

