Restored from previous forum. Originally posted by SimpleMind.
Hi,
I read discussions about how to get the drive names in your system. I saw some code of Freak and came up with this one. It comes up with the name in the format A:\, C:\ etc. For me it was also a test case to understand those [...] pointers. But you guys here helped me a lot with your discussion about pointers here.
;Author: M.Kollenaar
;Date: 26 january 2003
;Version: 1.0
;Purpose: Get a list of drives present in this system.
;I got the idea from Freak. He used GetLogicalDrives to get a list of drives present in the system.
;I use in this code GetLogicalDriveStrings().
;Use Win32Api function.
;DWORD GetLogicalDriveStrings(
; DWORD nBufferLength, // size of buffer
; LPTSTR lpBuffer // address of buffer For drive strings
; );
;The returned drive string has the following format A:\C:\...Z:\ also 4 bytes for
;each drive and at the end two terminating string characters. If there are 26 possible drive letters
;allocate a buffer of 105 bytes (4*26)+1.
;
;Calculate memory buffer.
nBufferLength = (4*26)+1
;Get the buffer and startaddress.
*npBuffer = AllocateMemory(0, nBufferLength , 0)
;Check if memory allocation succeeded.
If *npBuffer 0
;Get drives and put the returned stringlength on a var.
stringlength = GetLogicalDriveStrings_(nBufferLength,*npBuffer)
;The number of drives in this system.
NumberOfDrives = stringlength/4
;Step through the drive string.
For i = 0 To NumberOfDrives - 1
;Get the drives names on intervals of 4 bytes.
Drive.s = PeekS(*npBuffer+(i*4))
;Show the drive names.
MessageRequester("DRIVES",Drive,0)
Next i
Else
;Something went wrong.
MessageRequester("Memory","No memory allocated",0)
EndIf
End
SimpleMind,
Whatever you can do or hope you can do, do it.
There lies ingenuity, power and magic in audacity.
Johan Wolfgang von Goethe
- Registered PureBasic Coder. -
