|
-
Jun 10th, 2003, 01:55 PM
#1
Thread Starter
Hyperactive Member
Getting Disk Label from DVD-Drive
Hi,
I have been using this code for some time to get the name of the currenty disk in the DVD-Drive.
VB Code:
Dim VI As VolumeInfo
'getVolumeInfo
Private Type VolumeInfo
Serial As Long
VolumeName As String
FileSystemName As String
End Type
Private Function GetVolumeInfo(Drive As String) As VolumeInfo
Dim tmp As VolumeInfo
tmp.VolumeName = Space(255)
tmp.FileSystemName = Space(255)
GetVolumeInformation Drive & ":\", tmp.VolumeName, 255, tmp.Serial, 0, 0, tmp.FileSystemName, 255
tmp.VolumeName = Trim(tmp.VolumeName)
tmp.FileSystemName = Trim(tmp.FileSystemName)
GetVolumeInfo = tmp
End Function
Then to put the actual disk label into a text box I have...
VB Code:
vi2 = GetVolumeInfo(letter)
Text23 = vi2.VolumeName
It works and I put the above two lines into a timer in order to get the text box updated. However no matter how fast I set the timer, like 100ms, 200ms, 500ms, there is always a massive delay.
Eg. Say I have AMERICAN PIE in at the minute. My text box shows it fine. Now I eject the tray and the text box will stay saying AMERICAN PIE for about 8 seconds. The whole program seems to freeze up for those few seconds.
Has anyone got any better code for getting the disk name. Looking in "MY COMPUTER", windows updates the disk name in a split second.
Any help would be greatly appreciated. I tried using windows own code to get notified when a disk was inserted but I couldn't get it to work if my program wasn't focused.
Thanks!!!!!!
KT
Last edited by King_Tweaker; Jun 10th, 2003 at 01:59 PM.
-
Jun 10th, 2003, 02:38 PM
#2
Thread Starter
Hyperactive Member
Anyone??
Can it be that visual basic is just so slow that it can't get the disk name in 8 seconds?
I will see if I can find a C++ example of this using the same getvolumeinformation.
Please guys, can anyone get this to work in any sort of fast time at all, even less than 1 seconds would be good.
KT
-
Jun 10th, 2003, 03:24 PM
#3
This should do it :
VB Code:
Option Explicit
Private Declare Function GetDriveType Lib "Kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
Private Declare Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) As Long
Private Sub Form_Load()
Dim intLetterCounter As Integer
Dim intElementCounter As Integer
Dim lngSerial As Long
Dim strVolumeName As String
Dim lngRetVal As Long
intElementCounter = 0
For intLetterCounter = 65 To 90
If (GetDriveType(Chr(intLetterCounter) & ":\") = 5) Then
strVolumeName = String(255, Chr(0))
GetVolumeInformation Chr(intLetterCounter) & ":\", strVolumeName, 255, lngSerial, 0, 0, 0, 255
MsgBox strVolumeName
End If
Next
End Sub
Has someone helped you? Then you can Rate their helpful post. 
-
Jun 10th, 2003, 04:13 PM
#4
Thread Starter
Hyperactive Member
Thanks but it does the exact same thing. See I have a text box and when the text box is updated with a new disk name it does some stuff like disable autorun etc.
But with this code and the one I was using earlier, it takes for ever for the text box to update itself.
Here is how I modified your code to simply test it out on my drive "F:\"
Again it works fine but when I eject the disk it takes a fair few seconds for the text box to get updated. Is it just text boxes or something. I will try again without using text boxes and just pure variables.
I tried all timer intervals like 100, 500, 1000, doesnt make a diff?
KT
VB Code:
Private Sub Timer1_Timer()
Dim intLetterCounter As Integer
Dim intElementCounter As Integer
Dim lngSerial As Long
Dim strVolumeName As String
Dim lngRetVal As Long
intElementCounter = 0
strVolumeName = String(255, Chr(0))
GetVolumeInformation "F:\", strVolumeName, 255, lngSerial, 0, 0, 0, 255
Text1 = strVolumeName
End Sub
-
Jun 10th, 2003, 08:12 PM
#5
Thread Starter
Hyperactive Member
OK
I have narrowed it down to one thing!!
The visual basic timers.
I have tried all types of techniques, from using the fso to detect when a disk was in, using mci stuff, using getvolumeinformation and all had this massive delay. It usually takes around 7 seconds for basic to detect there is no disk in the drive.
BUT simply putting the code in a button, and clicking that button 1 second after the drive is ejected correctly tells me "There is no disk in the drive"
What is it with the vb timers. Its like as if the timers totally stall and there is this massive backlog of timercode that gets done after the disk is ejected. I need to come up with some way to make the timer check if a disk is in but not stall.
Does anyone have a technique for doing this. I was thinking of using the windows time somehow to make the timer recognize if its in some stall period.
Please guys, I need you experts to help me out.
Try the code out for yourselves if you like. Here is a simple set of code if you want to see for yourself what I am talking about.
All you need is this code, a timer and a textbox. You will see yourself the code works fine but no matter what interval you give the timer, upon ejecting a disk it takes forever to update the textbox. If you then put the timer code into a text box and disable the timer, you will see that manually clicking the button at any time works fine!
VB Code:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Function IsCDInDrive(ByVal strCDDriveLetter As String) As Boolean
Dim strStatus As String * 128
'open the device
mciSendString "open " & strCDDriveLetter & ": type cdaudio alias cddrive wait", vbNullString, 0, 0
'see if there's something in the drive
mciSendString "status cddrive media present", strStatus, Len(strStatus), 0
'close the device
mciSendString "close cddrive", vbNullString, 0, 0
'the string will contain "true" or "false" which can be easily converted
IsCDInDrive = CBool(Left$(strStatus, InStr(strStatus, vbNullChar) - 1))
End Function
Private Sub Timer1_Timer()
Text1 = IsCDInDrive("F")
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|