home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "InfoComp"
- ' Questo Φ un file dimostrativo sull'uso delle API in VB
- ' Φ stato creato per la rivista ioProgrammo della DiemmeEditori
- ' dal Prof. Francesco Mannarino - Italy
- ' il 19 Aprile 1998
- Option Explicit
- 'Funzione API GetSystemInfo()
- Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As _
- SYSTEM_INFO)
-
- ' Funzione API GetVolumeInformation
- Declare Function GetVolumeInformation Lib _
- "kernel32" Alias "GetVolumeInformationA" _
- (ByVal lpRootPathName As String, _
- ByVal lpVolumeNameBuffer As String, _
- ByVal nVolumeNameSize As Long, _
- lpVolumeSerialNumber As Long, _
- lpMaximumComponentLength As Long, _
- lpFileSystemFlags As Long, _
- ByVal lpFileSystemNameBuffer As String, _
- ByVal nFileSystemNameSize As Long) As Long
-
- ' Funzione API GetDiskFreeSpace
- Declare Function GetDiskFreeSpace Lib _
- "kernel32" Alias "GetDiskFreeSpaceA" _
- (ByVal lpRootPathName As String, _
- lpSectorsPerCluster As Long, _
- lpBytesPerSector As Long, _
- lpNumberOfFreeClusters As Long, _
- lpTtoalNumberOfClusters As Long) As Long
-
- 'costanti di GetSystemInfo()
- Public Const PROCESSOR_INTEL_386 = 386
- Public Const PROCESSOR_INTEL_486 = 486
- Public Const PROCESSOR_INTEL_PENTIUM = 586
- Public Const PROCESSOR_MIPS_R4000 = 4000
- Public Const PROCESSOR_ALPHA_21064 = 21064
-
- ' struttura di GetSystemInfo()
- Type SYSTEM_INFO
- dwOemID As Long
- dwPageSize As Long
- lpMinimumApplicationAddress As Long
- lpMaximumApplicationAddress As Long
- dwActiveProcessorMask As Long
- dwNumberOrfProcessors As Long
- dwProcessorType As Long
- dwAllocationGranularity As Long
- dwReserved As Long
- End Type
-
- ' istanza sulla struttura SYSTEM_INFO
- Public MySystemInfo As SYSTEM_INFO
-
- ' Funzione API GetVersionEx()
- Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
- (LpVersionInformation As OSVERSIONINFO) As Long
-
- ' Struttura di GetVersionEx()
- Type OSVERSIONINFO
- dwOSVersionInfoSize As Long
- dwMajorVersion As Long
- dwMinorVersion As Long
- dwBuildNumber As Long
- dwPlatformId As Long
- szCSDVersion As String * 128
- End Type
-
- ' Funzione API GlobalMemoryStatus()
- Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As _
- MEMORYSTATUS)
-
- ' Struttura di GlobalMemoryStatus
- 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
-
- '-------------------------------------------------
-
- ' Tipi personalizzati per reperire i dati su
- ' GetDiskFreeSpace() GetVolumeInformation()
- Public Type ElementiHd
- Percorso As String
- NomeVolume As String
- NrVolNameS As Long
- NrSeriale As Long
- MaxComp As Long
- FlSysFlag As Long
- FlSysNamS As String
- NrFlSysNamS As Long
- End Type
-
- Public Type DiscoFisico
- lpSectorsPerCluster As Long
- lpBytesPerSector As Long
- lpNumberOfFreeClusters As Long
- lpTtoalNumberOfClusters As Long
- End Type
-
- ' variabili sui tipi ElementiHd e DiscoFisico
- Dim MioHd As ElementiHd
- Dim MioHdFis As DiscoFisico
-
- ' funzione che chiama e formatta i dati di GetVolumeInformation
- Public Function InfoHD(ByVal MioDrive As String) As Long
- Dim temp&
- Dim StrNulNomeVol$, StrNulFlSys$
- StrNulNomeVol$ = String$(256, 0)
- StrNulFlSys$ = String$(256, 0)
- temp = GetVolumeInformation(MioDrive, _
- StrNulNomeVol$, 255, MioHd.NrSeriale, _
- MioHd.MaxComp, MioHd.FlSysFlag, StrNulFlSys$, 255)
- InfoHD = temp
- MioHd.NomeVolume = StrNulToStr(StrNulNomeVol$)
- MioHd.FlSysNamS = StrNulToStr(StrNulFlSys$)
- End Function
-
- ' funzione che chiama e formatta i dati di GetDiskFreeSpace
- Public Function InfoFisHd(ByVal MioDrive As String) As Long
- Dim temp&
- temp = GetDiskFreeSpace(MioDrive, _
- MioHdFis.lpSectorsPerCluster, _
- MioHdFis.lpBytesPerSector, _
- MioHdFis.lpNumberOfFreeClusters, _
- MioHdFis.lpTtoalNumberOfClusters)
- InfoFisHd = temp
- End Function
-
- Public Function NomeVolume()
- NomeVolume = MioHd.NomeVolume
- End Function
- Public Function NrSeriale()
- NrSeriale = MioHd.NrSeriale
- End Function
- Public Function MaxComp()
- MaxComp = MioHd.MaxComp
- End Function
- Public Function FlSysFlag()
- FlSysFlag = MioHd.FlSysFlag
- End Function
- Public Function FlSysNamS()
- FlSysNamS = MioHd.FlSysNamS
- End Function
- Public Function SettoriPerCluster()
- SettoriPerCluster = MioHdFis.lpSectorsPerCluster
- End Function
- Public Function BytesPerSettori()
- BytesPerSettori = MioHdFis.lpBytesPerSector
- End Function
- Public Function NrClusterLiberi()
- NrClusterLiberi = MioHdFis.lpNumberOfFreeClusters
- End Function
- Public Function TotNrCluster()
- TotNrCluster = MioHdFis.lpTtoalNumberOfClusters
- End Function
- Public Function Capienzahd()
- Capienzahd = SettoriPerCluster * BytesPerSettori * TotNrCluster
- End Function
-
- ' funzione che trasforma un stringa terminante con zero
- ' in una senza
- Public Function StrNulToStr(ByVal Str_Nul$) As String
- Dim k As Integer
- For k = 1 To 256
- If Asc(Mid(Str_Nul$, k, 1)) = 0 Then Exit For
- StrNulToStr = StrNulToStr + Mid(Str_Nul$, k, 1)
- Next
- End Function
-