Powerbasic Museum 2020-B

Webmaster: José Roca (PBWIN 10+/PBCC 6+) (SDK Forum) => Windows API Programming => Topic started by: José Roca on August 29, 2011, 03:10:37 AM

Title: Volume Management Functions Examples
Post by: José Roca on August 29, 2011, 03:10:37 AM
 
Volumes are implemented by a device driver called a volume manager. Examples include the FtDisk Manager, the Logical Disk Manager (LDM), and the VERITAS Logical Volume Manager (LVM). Volume managers provide a layer of physical abstraction, data protection (using some form of RAID), and performance.
Title: WINAPI: GetDriveType Function
Post by: José Roca on August 29, 2011, 03:11:54 AM
 
The following example illustrates the use of the GetDriveType function.


' ########################################################################################
' The following example illustrates the use of the GetDriveType function.
' ########################################################################################

#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL dwBufLen AS DWORD
   LOCAL strBuffer AS STRING
   LOCAL nDrives aS LONG
   LOCAL szDrive AS ASCIIZ * 4
   LOCAL i AS LONG

   ' Retrieve the need buffer length
   dwBufLen = GetLogicalDriveStrings(0, BYVAL %NULL)
   ' Prepare a long enough buffer
   strBuffer = STRING$(dwBufLen, $NUL)
   ' Get the list of drives
   GetLogicalDriveStrings(dwBufLen, BYVAL STRPTR(strBuffer))
   ' Trim the last two nuls
   strBuffer = RTRIM$(strBuffer, $NUL)
   ' Retrieve the number of drives in the list
   nDrives = PARSECOUNT(strBuffer, $NUL)
   ' Parse the list
   FOR i = 1 TO nDrives
      szDrive = PARSE$(strBuffer, $NUL, i)
      SELECT CASE GetDriveType(szDrive)
         CASE %DRIVE_FIXED    : ? szDrive & " Type: Fixed"
         CASE %DRIVE_REMOTE   : ? szDrive & " Type: Remote"
         CASE %DRIVE_REMOVABLE: ? szDrive & " Type: Removable"
         CASE %DRIVE_CDROM    : ? szDrive & " Type: CD-ROM"
         CASE %DRIVE_RAMDISK  : ? szDrive & " Type: RAMDISK"
         CASE ELSE            : ? szDrive & " Type: Unknown Type"
      END SELECT
   NEXT

   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION
' ========================================================================================

Title: WINAPI: GetLogicalDrives Function
Post by: José Roca on August 29, 2011, 03:12:50 AM
 
The following example illustrates the use of the GetLogicalDrives function.


#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

FUNCTION PBMAIN () AS LONG

   LOCAL nMask AS LONG
   LOCAL i AS LONG
   
   nMask = GetLogicalDrives
   FOR i = 0 TO 25
      IF BIT(nMask, i) THEN
         ? "Drive: " & CHR$(i + 65)
      END IF
   NEXT
   
   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION

Title: WINAPI: GetLogicalDriveStrings Function
Post by: José Roca on August 29, 2011, 03:13:37 AM
 
The following example illustrates the use of the GetLocalDriveStrings function.


' ########################################################################################
' The following example illustrates the use of the GetLogicalDriveStrings function.
' ########################################################################################

#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL dwBufLen AS DWORD
   LOCAL strBuffer AS STRING
   LOCAL nDrives aS LONG
   LOCAL strDrive AS STRING
   LOCAL i AS LONG

   ' Retrieve the need buffer length
   dwBufLen = GetLogicalDriveStrings(0, BYVAL %NULL)
   ' Prepare a long enough buffer
   strBuffer = STRING$(dwBufLen, $NUL)
   ' Get the list of drives
   GetLogicalDriveStrings(dwBufLen, BYVAL STRPTR(strBuffer))
   ' Trim the last two nuls
   strBuffer = RTRIM$(strBuffer, $NUL)
   ' Retrieve the number of drives in the list
   nDrives = PARSECOUNT(strBuffer, $NUL)
   ' Parse the list
   FOR i = 1 TO nDrives
      strDrive = PARSE$(strBuffer, $NUL, i)
      ? strDrive
   NEXT

   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION
' ========================================================================================