RE: GetDrives in Win32 Help Needed
- Posted by Al Getz <Xaxo at aol.com> Apr 19, 2001
- 409 views
CK Lester wrote: > I'm trying to get the drives on a Win95 pre-SR2 release... It seems to > choke > on the "GetDiskFreeSpaceEx" because it can't find it in "kernel32.dll." > Can > somebody fix it so it just ignore this, or is it (the free space) > required > to get the drive status? > > Thanks! > ck > > > > > > Hi there ck, If you cant use GetDiskFreeSpaceEx() you can use GetDiskFreeSpace() but your return values are limited to 2 gigabyte disk size, but thats good enough to tell if your ap has enough free disk space because even if the disk is really 20 GB if it has at least 2GB free GetDiskFreeSpace() will show 2GB, which is usually more than enough space for most stuff. Heres a reprint of a previous post: ----------------------------------- include dll.e include msgbox.e global atom hKernel32_dll,hGetLogicalDrives,hGetDiskFreeSpace atom retv hKernel32_dll=open_dll("kernel32.dll") if hKernel32_dll=0 then retv=message_box( "could not locate Kernel32.dll","GetDrives.exw",MB_ICONHAND+MB_TASKMODAL ) abort(1) end if hGetLogicalDrives= define_c_func(hKernel32_dll, "GetLogicalDrives", {}, C_ULONG) if hGetLogicalDrives<0 then retv=message_box( "could not link to c function"DA& "GetLogicalDrives in Kernel32.dll", "GetDrives.exw",MB_ICONHAND+MB_TASKMODAL) abort(1) end if hGetDiskFreeSpace= define_c_func(hKernel32_dll, "GetDiskFreeSpaceA", {C_POINTER,C_POINTER,C_POINTER,C_POINTER,C_POINTER}, C_ULONG) if hGetDiskFreeSpace<0 then retv=message_box( "could not link to c function"DA& "GetDiskFreeSpace in Kernel32.dll","GetDrives.exw", MB_ICONHAND+MB_TASKMODAL) abort(1) end if function GetDiskFreeSpace(sequence drive) atom lpPathName,lpSectorsPerCluster,lpBytesPerSector, lpNumberOfFreeClusters,lpTotalNumberOfClusters,bool sequence info lpPathName=allocate_string(drive) lpSectorsPerCluster=allocate(4) lpBytesPerSector=allocate(4) lpNumberOfFreeClusters=allocate(4) lpTotalNumberOfClusters=allocate(4) bool=c_func(hGetDiskFreeSpace, {lpPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters}) info={ bool, peek4u(lpSectorsPerCluster), peek4u(lpBytesPerSector), peek4u(lpNumberOfFreeClusters), peek4u(lpTotalNumberOfClusters) } --warning: --this function shows bytes up to 2gig drive limit, --but thats good enough for most aps needing to know --if there is free space available. --If you have the newer win95+ use GetDrivesInfo(). free(lpPathName) free(lpSectorsPerCluster) free(lpBytesPerSector) free(lpNumberOfFreeClusters) free(lpTotalNumberOfClusters) return info end function retv=c_func(hGetLogicalDrives,{}) sequence message,windows_crlf,drive,Drives,DrivesReady,info windows_crlf=#0DA Drives={} DrivesReady={} atom bit integer DriveLetter message="Drives available and ready:"&windows_crlf bit=1 for k=1 to 26 do if and_bits(bit,retv) then DriveLetter=k+96--change to "DriveLetter=k+64" for caps drive=DriveLetter&":\\" info=GetDiskFreeSpace(drive) if info[1] then info=info[2..length(info)] message=message&drive&windows_crlf DrivesReady=append(DrivesReady,drive) end if Drives=append(Drives,drive) end if bit=bit*2 end for ?Drives --sequence of all drives available on the system puts(1,"\n") --display all drives in the system to console: for k=1 to length(Drives) do printf(1,"%s\n",{Drives[k]}) end for --display all drives available and ready in message box: retv=message_box( message,"GetDrives.exw",MB_TASKMODAL )