GetDrives() and GetDrivesReady() wrapped
- Posted by Al Getz <Xaxo at aol.com> Apr 11, 2001
- 461 views
Hi again Derek, Here's wrapped functions to get drives as well as determine which ones are ready. You might want to include that as well. --Al ----------------------------------- 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: disregard all info except 'bool' --as this function is stuck on the old 2gig drive limit. 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 )