GetLogicalDriveString32()

Purpose

The GetLogicalDriveStrings function fills a buffer with strings that specify valid drives in the system. GetLogicalDriveString32 is its implementation for MapBasic and works only with A (ANSI) flavour of that function.

 

Calls to GetLogicalDriveStrings() return the system drive strings in an array (e.g. "a:\, b:\, etc."). However the API function returns this as a single string with null byte delimiters, and MapInfo can't handle strings with null bytes in them. Instead we pass an array of integers and parse the bytes into a MapInfo string. The WinAPI declaration must be modifed as well, but this works because strings and integer arrays are mapped into the same memory space on the stack.

 
Library Transcribed by Date of page Updated on
Kernel32.dll J.Paris on the basis of Bill Thoen example 25.04.06  
 
Restrictions on use
Requires Windows NT 3.1 or later; Requires Windows 95 or later
 
Declare 32-bit

declare function GetLogicalDriveString32 lib "kernel32" alias "GetLogicalDriveStringsA"

    (byval nBufferLength as integer,

    sBuffer() as integer

    )as integer

 
Required Type definition
 
 
Parameters

nBufferLength

Specifies the maximum size of the array pointed to by sBuffer.

 

sBuffer()

Points to an array of integers, one for each valid drive in the system.

 
Return value

If the function succeeds, the return value is the number of integers in the array
If the function fails, the return value is zero.

 
Example

'Adapted from Bill Thoen's AddDirInto example

 

declare function GetLogicalDriveString32 lib "kernel32" alias "GetLogicalDriveStringsA"

    (byval nBufferLength as integer, sBuffer() as integer)as integer

 

dim sBuffer as string

dim ret, i as smallint

dim ncount, n, sChar() as integer

 

nCount = 128

redim sChar(nCount)

nCount = GetLogicalDriveString32 (nCount*4, sChar)

sBuffer = ""

'Convert 4 bytes of integer into 4 bytes of string.

'Note that byte order for integers is reversed from byte-order of strings.

for i = 1 to nCount\4

  n = (sChar(i) \ 256^0) mod 256

  if n = 0 then n = asc(" ") end if

  sBuffer = sBuffer + chr$(n)

  n = (sChar(i) \ 256^1) mod 256

  if n = 0 then n = asc(" ") end if

  sBuffer = sBuffer + chr$(n)

  n = (sChar(i) \ 256^2) mod 256

  if n = 0 then n = asc(" ") end if

  sBuffer = sBuffer + chr$(n)

  n = (sChar(i) \ 256^3) mod 256

  i f n = 0 then n = asc(" ") end if

  sBuffer = sBuffer + chr$(n)

next

note "Installed drives :"+chr$(10)+chr$(10)+sbuffer

 
Comments
 
 
See also

 Bill Thoen AddDirInto example