home *** CD-ROM | disk | FTP | other *** search
Wrap
Visual Basic class definition | 2001-12-02 | 6.8 KB | 213 lines
VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "MemoryStatus" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit ' Memory information class. Private Type MemoryStatus dwLength As Long dwMemoryLoad As Long dwTotalPhys As Long dwAvailPhys As Long dwTotalPageFile As Long dwAvailPageFile As Long dwTotalVirtual As Long dwAvailVirtual As Long End Type Private ms As MemoryStatus Private Type MEMORYSTATUSEX dwLength As Long dwMemoryLoad As Long ullTotalPhys As Currency ullAvailPhys As Currency ullTotalPageFile As Currency ullAvailPageFile As Currency ullTotalVirtual As Currency ullAvailVirtual As Currency ullAvailExtendedVirtual As Currency End Type Private msEx As MEMORYSTATUSEX Private Declare Sub GlobalMemoryStatus _ Lib "kernel32" _ (lpBuffer As MemoryStatus) Private Declare Sub GlobalMemoryStatusEx _ Lib "kernel32" _ (lpBuffer As MEMORYSTATUSEX) ' 5113 is arbitrary. Private Const dhcErrBase = vbObjectError + 5113 Private Const ERR_STRING = "Invalid for this operating system." Private Const ERR_INVALID_OS = dhcErrBase + 1 Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Private osvi As OSVERSIONINFO Private Declare Function GetVersionEx _ Lib "kernel32" Alias "GetVersionExA" _ (lpVersionInformation As Any) As Long Private mblnIsWin2000 As Boolean ' Should this class raise errors if the ' operating system doesn't support the ' requested operation, or should it silently fail? Public RaiseErrors As Boolean Public Property Get MemoryLoad() As Long ' Number between 0 and 100 that gives a general idea ' of current memory utilization, in which 0 indicates ' no memory use and 100 indicates full memory use. If mblnIsWin2000 Then Call GlobalMemoryStatusEx(msEx) MemoryLoad = msEx.dwMemoryLoad Else Call GlobalMemoryStatus(ms) MemoryLoad = ms.dwMemoryLoad End If End Property Public Property Get TotalPhysical() As Long ' Indicates the total number of bytes of physical memory. If mblnIsWin2000 Then Call GlobalMemoryStatusEx(msEx) TotalPhysical = CurrencyToLong(msEx.ullTotalPhys) Else Call GlobalMemoryStatus(ms) TotalPhysical = ms.dwTotalPhys End If End Property Public Property Get AvailablePhysical() As Long ' Indicates the number of bytes of physical memory available. If mblnIsWin2000 Then Call GlobalMemoryStatusEx(msEx) AvailablePhysical = CurrencyToLong(msEx.ullAvailPhys) Else Call GlobalMemoryStatus(ms) AvailablePhysical = ms.dwAvailPhys End If End Property Public Property Get TotalPageFile() As Long ' Indicates the total number of bytes that can be stored ' in the paging file, not the size of the paging file on disk. If mblnIsWin2000 Then Call GlobalMemoryStatusEx(msEx) TotalPageFile = CurrencyToLong(msEx.ullTotalPageFile) Else Call GlobalMemoryStatus(ms) TotalPageFile = ms.dwTotalPageFile End If End Property Public Property Get AvailablePageFile() As Long ' Indicates the number of bytes available in the paging file. If mblnIsWin2000 Then Call GlobalMemoryStatusEx(msEx) AvailablePageFile = CurrencyToLong(msEx.ullAvailPageFile) Else Call GlobalMemoryStatus(ms) AvailablePageFile = ms.dwAvailPageFile End If End Property Public Property Get TotalVirtual() As Long ' Indicates the total number of bytes ' that can be described in the user mode ' portion of the virtual address space ' of the calling process. If mblnIsWin2000 Then Call GlobalMemoryStatusEx(msEx) TotalVirtual = CurrencyToLong(msEx.ullTotalVirtual) Else Call GlobalMemoryStatus(ms) TotalVirtual = ms.dwTotalVirtual End If End Property Public Property Get AvailableVirtual() As Long ' Indicates the number of bytes of unreserved and ' uncommitted memory in the user mode portion ' of the virtual address space of the calling process. If mblnIsWin2000 Then Call GlobalMemoryStatusEx(msEx) AvailableVirtual = CurrencyToLong(msEx.ullAvailVirtual) Else Call GlobalMemoryStatus(ms) AvailableVirtual = ms.dwAvailVirtual End If End Property Public Property Get AvailableExtendedVirtual() As Long ' Indicates the number of bytes of unreserved and ' uncommitted memory in the VLM portion of the ' virtual address space of the calling process. The ' total memory available in VLM space is 28 GB. ' Win2000 only If mblnIsWin2000 Then Call GlobalMemoryStatusEx(msEx) AvailableExtendedVirtual = CurrencyToLong(msEx.ullAvailExtendedVirtual) Else Call HandleErrors(fer As MemorySHnsEx(msEx) AvailableExtendedVirtua L_(umber o ic Propibalong(msExaey Private mblnIsWin2000 As Boolean ' Should this class raise errors if the ' operating system d OSVERi ' opn e As Boo As Boolean '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 ' Intaes full memi _nhhagx(mTescribea) As Lo3() As rAL, Pubvl memory use. drn3 Pn r4Ttn portion of the ' Intaes fuge 'Eh_rttua L_h_rttu000 As nwvtTtn portion of tf"E uA 'Eh_rRa L_h AvailablePaan 'Eh_rttua) blePaalablePaan lAs BoorMSL_h s iEh_rttue. dt Long SyBa ahhagxMroae dt Longtan 'EhsblePaana)ailV_e dt Longtan 'EhsblePaana)ailV_e dt Long iEh_rttue. dt Long SyBa ahhagxMroae nttua aery us0lzse. dt LIescribea) As LofBEfrIf fbleP 'EhsblePaana)ailV_e dtEis' unld 'Ehs_ (ailV_e LEh_rttua nbHandleEr wlePaan lus(ms) l ailV_e dtL unld 'Ehs_SrV_e dtEis' dwThe )Ttnirtu)Virtua L_(umbesedVirrrrrrrrrrrlePaan lus(ms)ew atvelPh'EhSdFePaanDuion e As BBooEdvmua use. drn3 Pn niiiiiiidtAua L_(umbend If Eh 'EhsblePaana)ailV_e dt Longtan 'EhsblePaana)ailV_e dt Long iEh_rttue. dt Long SyltailV_e dt Longrr + 511 a use. drn3 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 Pn niiiiiiemory utilizatio=mroaatAEf b atvelPh'EhSdFeilV_e dtdttue. dLnry utilizatio=mrearooSae nttua aerythatAEi iEh_(vcew az