Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When is the CD is ejected

Status
Not open for further replies.

aaahhhrrggghhhh

Programmer
Apr 5, 2002
61
IE
Hi all.

I have a form that has a drivebox. I need to know when the user physically ejects the CD from the drive that the drivebox is currently viewing.

1. User puts cd into drive
2. User selects the drive letter from the drivebox
3. User presses the button on the cd rom drive to eject it.
4. If the cd is extracted from the drive plate, therefore removed, how can I get VB to call a specific function one this happens? Easy Cd Creator does it if you try to eject a CD as it is writing, so hopefully its possible (I'm sure the writers of EasyCD creator used C++)

I thaught about using a timer to check constantly what has been removed since the last check, but this would be resource intensive, and basically against the point of using callbacks. I am presuming that the windows API would probably be rearing its head here somewhere, but I cant find the function to do it.

Please can anybody help?
Cheers.


Dont be small. be BIG
 
try using the fileSystemObject for the drive, and then use the following:

fso.Drives(key).IsReady=true

Good luck

BB
 
Thanks BB, but this would probably exist in an If statement. This isn't what I am looking for, precisely although It does interest me. I am looking for an entry point in code which is executed when the user physically presses eject on the CD casing.

Cheers,
Nick.

Dont be small. be BIG
 
Just add the "Microsoft SysInfo Control" component to your project.
It has the events:
Private Sub SysInfo1_DeviceArrival(ByVal DeviceType As Long, ByVal DeviceID As Long, ByVal DeviceName As String, ByVal DeviceData As Long)
If DeviceType = 2 Then
Debug.Print "Device ID: " & DeviceID & vbCr & "Device Name: " & DeviceName
End If
End Sub

Private Sub SysInfo1_DeviceRemoveComplete(ByVal DeviceType As Long, ByVal DeviceID As Long, ByVal DeviceName As String, ByVal DeviceData As Long)
If DeviceType = 2 Then
Debug.Print "Device ID: " & DeviceID & vbCr & "Device Name: " & DeviceName
End If
End Sub

 
Thanks CCLint (I have heard that phrase before, unix??)

Anyway, Will test your idea. I understand what to do and forsee that this should work in theory. Wouldn't it be good if VB provided a method to do this without reverting to ActiveX?

Doesn't C++ resolve this issue without dll's?

Nick.

Dont be small. be BIG
 
>Wouldn't it be good if VB provided a method to do this without reverting to ActiveX

Why? VB isn't a disk or network operating system. Where would you draw the line for native events/functions/methods? The whole point of ActiveX is to add new functionality...
 
I understand, but instead of incorporating ActiveX functionality why not use callback methods instead, in order to minimize the number of dlls/ocx's loaded. It could also be that both ActiveX and Callbacks are equal options. Its just that I'm getting more into using the API functions that I would like to see an API function that recieves status information from devices so that the users can use a public declare command, to simplify (in my opinion), this.

I probably dont go with the general crowd on this opinion, but this is the way Id like to see it done, rather than adding another file to the list of project files for the system to load when my project is run, which zaps more resources.

Much thanks to CCLINT for his suggestion though, will try later.

Dont be small. be BIG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top