Problem with GetDriveType in VB.Net and Windows XP

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to get the letter of the CD-Rom drive using a loop to go through
each drive letter and checking if GetDriveType(drive_letter) = 5 (for a cd
rom)

but it doesn't work, when i check what GetDriveType returns for my CD-Rom,
it returns 8975933078237085701. What the hell is that???
 
Jonathan Smith said:
I am trying to get the letter of the CD-Rom drive using a loop
to go through each drive letter and checking if
GetDriveType(drive_letter) = 5 (for a cd rom)

but it doesn't work, when i check what GetDriveType returns
for my CD-Rom, it returns 8975933078237085701. What the
hell is that???

"Post your code."
 
Herfried K. Wagner said:
"Post your code."

My code:

Private Declare Function GetDriveType Lib "kernel32" Alias _
"GetDriveTypeA" (ByVal nDrive As String) As Long
Private Const DRIVE_CDROM = 5

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load

MsgBox (GetDriveType("D:\")
End Sub

And the message box displays this long seemingly random number
 
Jonathan Smith said:
Private Declare Function GetDriveType Lib "kernel32" Alias _
"GetDriveTypeA" (ByVal nDrive As String) As Long

The return value should be an 'Int32'! This should fix your problem.

'Long' ('Int64') is a 64-bit datatype in .NET.
 
Herfried K. Wagner said:
The return value should be an 'Int32'! This should fix your problem.

'Long' ('Int64') is a 64-bit datatype in .NET.

A beginner's mistake, from a beginner

That's fixed the problem. Muchos thanks for your help

Regards

Jonathan Smith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top