home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CyberFreak387771212001.psc / MemoryStatus.cls < prev   
Encoding:
Visual Basic class definition  |  2001-12-02  |  6.8 KB  |  213 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "MemoryStatus"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. ' Memory information class.
  17.  
  18. Private Type MemoryStatus
  19.     dwLength As Long
  20.     dwMemoryLoad As Long
  21.     dwTotalPhys As Long
  22.     dwAvailPhys As Long
  23.     dwTotalPageFile As Long
  24.     dwAvailPageFile As Long
  25.     dwTotalVirtual As Long
  26.     dwAvailVirtual As Long
  27. End Type
  28. Private ms As MemoryStatus
  29.  
  30. Private Type MEMORYSTATUSEX
  31.     dwLength As Long
  32.     dwMemoryLoad As Long
  33.     ullTotalPhys As Currency
  34.     ullAvailPhys As Currency
  35.     ullTotalPageFile As Currency
  36.     ullAvailPageFile As Currency
  37.     ullTotalVirtual As Currency
  38.     ullAvailVirtual As Currency
  39.     ullAvailExtendedVirtual As Currency
  40. End Type
  41. Private msEx As MEMORYSTATUSEX
  42.  
  43. Private Declare Sub GlobalMemoryStatus _
  44.  Lib "kernel32" _
  45.  (lpBuffer As MemoryStatus)
  46.  
  47. Private Declare Sub GlobalMemoryStatusEx _
  48.  Lib "kernel32" _
  49.  (lpBuffer As MEMORYSTATUSEX)
  50.  
  51. ' 5113 is arbitrary.
  52. Private Const dhcErrBase = vbObjectError + 5113
  53. Private Const ERR_STRING = "Invalid for this operating system."
  54. Private Const ERR_INVALID_OS = dhcErrBase + 1
  55.  
  56. Private Type OSVERSIONINFO
  57.     dwOSVersionInfoSize As Long
  58.     dwMajorVersion As Long
  59.     dwMinorVersion As Long
  60.     dwBuildNumber As Long
  61.     dwPlatformId As Long
  62.     szCSDVersion As String * 128
  63. End Type
  64. Private osvi As OSVERSIONINFO
  65.  
  66. Private Declare Function GetVersionEx _
  67.  Lib "kernel32" Alias "GetVersionExA" _
  68.  (lpVersionInformation As Any) As Long
  69.  
  70. Private mblnIsWin2000 As Boolean
  71.  
  72. ' Should this class raise errors if the
  73. ' operating system doesn't support the
  74. ' requested operation, or should it silently fail?
  75. Public RaiseErrors As Boolean
  76.  
  77. Public Property Get MemoryLoad() As Long
  78.     ' Number between 0 and 100 that gives a general idea
  79.     ' of current memory utilization, in which 0 indicates
  80.     ' no memory use and 100 indicates full memory use.
  81.     If mblnIsWin2000 Then
  82.         Call GlobalMemoryStatusEx(msEx)
  83.         MemoryLoad = msEx.dwMemoryLoad
  84.     Else
  85.         Call GlobalMemoryStatus(ms)
  86.         MemoryLoad = ms.dwMemoryLoad
  87.     End If
  88. End Property
  89.  
  90. Public Property Get TotalPhysical() As Long
  91.     ' Indicates the total number of bytes of physical memory.
  92.     If mblnIsWin2000 Then
  93.         Call GlobalMemoryStatusEx(msEx)
  94.         TotalPhysical = CurrencyToLong(msEx.ullTotalPhys)
  95.     Else
  96.         Call GlobalMemoryStatus(ms)
  97.         TotalPhysical = ms.dwTotalPhys
  98.     End If
  99. End Property
  100.  
  101. Public Property Get AvailablePhysical() As Long
  102.     ' Indicates the number of bytes of physical memory available.
  103.     If mblnIsWin2000 Then
  104.         Call GlobalMemoryStatusEx(msEx)
  105.         AvailablePhysical = CurrencyToLong(msEx.ullAvailPhys)
  106.     Else
  107.         Call GlobalMemoryStatus(ms)
  108.         AvailablePhysical = ms.dwAvailPhys
  109.     End If
  110. End Property
  111.  
  112. Public Property Get TotalPageFile() As Long
  113.     ' Indicates the total number of bytes that can be stored
  114.     ' in the paging file, not the size of the paging file on disk.
  115.     If mblnIsWin2000 Then
  116.         Call GlobalMemoryStatusEx(msEx)
  117.         TotalPageFile = CurrencyToLong(msEx.ullTotalPageFile)
  118.     Else
  119.         Call GlobalMemoryStatus(ms)
  120.         TotalPageFile = ms.dwTotalPageFile
  121.     End If
  122. End Property
  123.  
  124. Public Property Get AvailablePageFile() As Long
  125.     ' Indicates the number of bytes available in the paging file.
  126.     If mblnIsWin2000 Then
  127.         Call GlobalMemoryStatusEx(msEx)
  128.         AvailablePageFile = CurrencyToLong(msEx.ullAvailPageFile)
  129.     Else
  130.         Call GlobalMemoryStatus(ms)
  131.         AvailablePageFile = ms.dwAvailPageFile
  132.     End If
  133.  
  134. End Property
  135.  
  136. Public Property Get TotalVirtual() As Long
  137.     ' Indicates the total number of bytes
  138.     ' that can be described in the user mode
  139.     ' portion of the virtual address space
  140.     ' of the calling process.
  141.     If mblnIsWin2000 Then
  142.         Call GlobalMemoryStatusEx(msEx)
  143.         TotalVirtual = CurrencyToLong(msEx.ullTotalVirtual)
  144.     Else
  145.         Call GlobalMemoryStatus(ms)
  146.         TotalVirtual = ms.dwTotalVirtual
  147.     End If
  148. End Property
  149.  
  150. Public Property Get AvailableVirtual() As Long
  151.     ' Indicates the number of bytes of unreserved and
  152.     ' uncommitted memory in the user mode portion
  153.     ' of the virtual address space of the calling process.
  154.     If mblnIsWin2000 Then
  155.         Call GlobalMemoryStatusEx(msEx)
  156.         AvailableVirtual = CurrencyToLong(msEx.ullAvailVirtual)
  157.     Else
  158.         Call GlobalMemoryStatus(ms)
  159.         AvailableVirtual = ms.dwAvailVirtual
  160.     End If
  161. End Property
  162.  
  163. Public Property Get AvailableExtendedVirtual() As Long
  164.     ' Indicates the number of bytes of unreserved and
  165.     ' uncommitted memory in the VLM portion of the
  166.     ' virtual address space of the calling process. The
  167.     ' total memory available in VLM space is 28 GB.
  168.     ' Win2000 only
  169.     If mblnIsWin2000 Then
  170.         Call GlobalMemoryStatusEx(msEx)
  171.         AvailableExtendedVirtual = CurrencyToLong(msEx.ullAvailExtendedVirtual)
  172.     Else
  173.         Call HandleErrors(fer As MemorySHnsEx(msEx)
  174.         AvailableExtendedVirtua L_(umber o ic Propibalong(msExaey
  175. Private mblnIsWin2000 As Boolean
  176.  
  177. ' Should this class raise errors if the
  178. ' operating system d OSVERi 
  179. ' opn e  As Boo As Boolean
  180.  
  181. 'Eh_rttua L_h_rttu000 As n e  As iEh_rttua L_h_rttcalGdvlableExPhyelPhysicaltal='r)odvopn era As iEh_rttua L_ieTA roceBoo As BoorM sn000 dVirtuaunongPltaes full memory use. dt Long
  182.     ' Intaes full memi  _nhhagx(mTescribea) As Lo3() As rAL,
  183.  
  184. Pubvl memory use. drn3
  185. Pn   r4Ttn portion of the ' Intaes fuge 'Eh_rttua L_h_rttu000 As nwvtTtn portion of tf"E  uA 'Eh_rRa L_h
  186.         AvailablePaan
  187.  
  188. 'Eh_rttua)
  189.       blePaalablePaan
  190. lAs BoorMSL_h s iEh_rttue. dt Long
  191.   SyBa ahhagxMroae dt Longtan
  192.  
  193. 'EhsblePaana)ailV_e dt Longtan
  194.  
  195. 'EhsblePaana)ailV_e dt Long iEh_rttue. dt Long
  196.   SyBa ahhagxMroae nttua aery us0lzse. dt LIescribea) As LofBEfrIf fbleP
  197. 'EhsblePaana)ailV_e dtEis' unld  
  198. 'Ehs_
  199.  (ailV_e LEh_rttua nbHandleEr wlePaan
  200. lus(ms)
  201.   l ailV_e dtL unld  
  202. 'Ehs_SrV_e dtEis' 
  203.     dwThe )Ttnirtu)Virtua L_(umbesedVirrrrrrrrrrrlePaan
  204. lus(ms)ew atvelPh'EhSdFePaanDuion e  As BBooEdvmua  use. drn3
  205. Pn niiiiiiidtAua L_(umbend If
  206. Eh
  207.  
  208. 'EhsblePaana)ailV_e dt Longtan
  209.  
  210. 'EhsblePaana)ailV_e dt Long iEh_rttue. dt Long
  211.   SyltailV_e dt Longrr + 511 a  use. drn3
  212. Pn nr + 511tiV_e dtEis' er of bytes thatAEi iEh_rttue   tbytes thatAEf bytes thatAEi iEh_(vct Medttue. diMroaatAEf byteotrns thatAEf Ei iEh_ytewuOi_rtttue. diMroaatAErn3
  213. Pn niiiiiiemory utilizatio=mroaatAEf b atvelPh'EhSdFeilV_e dtdttue. dLnry utilizatio=mrearooSae nttua aerythatAEi iEh_(vcew az