GetDriveType() API Errors!

element

Active member
Joined
Oct 29, 2003
Messages
26
Location
Portsmouth, UK
I must admit this is the wierdest problem I have encountered with API and VB.NET...

Heres my simple debug code that I used to do some testing after my app was failing:

-- API --
Code:
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Const DRIVE_CDROM = 5
Const DRIVE_FIXED = 3
Const DRIVE_NO_ROOT = 1
Const DRIVE_REMOTE = 4
Const DRIVE_REMOVABLE = 2

And this is the actual code:

Code:
Debug.WriteLine("A:\ = " & GetDriveType("A:\"))
Debug.WriteLine("C:\ = " & GetDriveType("C:\"))
Debug.WriteLine("D:\ = " & GetDriveType("D:\")) cd
Debug.WriteLine("E:\ = " & GetDriveType("E:\"))
Debug.WriteLine("F:\ = " & GetDriveType("F:\"))
Debug.WriteLine("G:\ = " & GetDriveType("G:\"))
Debug.WriteLine("H:\ = " & GetDriveType("H:\")) cd
Debug.WriteLine("I:\ = " & GetDriveType("I:\"))

Both D and H are CD-ROM drives, as funnily enough I need to be able to filter out cd-rom drives from other drives. A:\ is a floppy, and the rest are hard drives.

These are my test results:

A:\ = 9222812402616107010
C:\ = 9222812402616107011
D:\ = 9222812402616107013
E:\ = 9222812402616107011
F:\ = 9222812402616107011
G:\ = 9222812402616107011
H:\ = 9222812402616107013
I:\ = 9222812402616107011

This seems to have no correspondence with the API specification, and although there is a pattern, how can I be sure that these strange numbers will be consistent on other machines etc???

Thanks for your help, Tom.
 
change the Long to Integer , then try this ....
Code:
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Integer

        Dim strDrives As String() = Environment.GetLogicalDrives()
        Dim drive As String
        For Each drive In strDrives
            Dim strType As String = GetDriveType(drive)
            Console.WriteLine(drive & " is type : " & strType)
        Next
itll give the numerics correctly , then you just need to replace them with the words ( eg: CD-ROM )
 
Back
Top