Eject the CD tray

rockman

Senior Member
Local time
Today, 12:05
Joined
May 29, 2002
Messages
190
Is it possible to code the CD-ROM tray to open/close?

Thanks,
Jeff
 
dont know how. but just curious why would you need to? Or is it just out of curiosity?
 
I've written code to prompt my end-user to back-up the data on a CD-RW. I present a dialog box "Please place the CD-ROM "Back-up Tuesday" in the drive."

I think it would just be cool to then have the drive tray open prompting the user to enter the disc.

(I other words... just because) :D
 
Use these API calls to do this:

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

Public Sub SetCDState(pbState As Boolean)
If pbState Then
  Call mciSendString("Set CDAudio Door Open", 0&, 0&, 0&)
Else
  Call mciSendString("Set CDAudio Door Closed", 0&, 0&, 0&)
End If
End Sub

Here are examples to call the function:

Code:
[COLOR=green]' Open CD tray with Command Button[/COLOR] 
Private Sub cmdClose_Click()
Call SetCDState(False)
End Sub

[COLOR=green]' Close CD tray with Command Button[/COLOR] 
Private Sub cmdOpen_Click()
Call SetCDState(True)
End Sub
HTH
RDH
 
I have seen other CD tray API's and that one wins for the fewest lines of code. I discovered that the open and close comments are backwards but it works! Thanks Ricky!
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

Public Function SetCDState(pbState As Boolean)
    If pbState Then
      Call mciSendString("Set CDAudio Door Open", 0&, 0&, 0&)
    Else
      Call mciSendString("Set CDAudio Door Closed", 0&, 0&, 0&)
    End If
End Function

' Close CD tray with Command Button
Public Function cmdClose_Click()
    Call SetCDState(False)
End Function

' Open CD tray with Command Button
Public Function cmdOpen_Click()
    Call SetCDState(True)
End Function
HTH
 
does anyone know where I can get a comprhensive list of api calls. I would love to get a list and mess around with them.
 
I'm glad that others are finding success with this code, but it not opening my CD-ROM tray. Perhaps it is a hardware problem on my end. Thanks for the input R. Hicks.
 
Create a small sample and add the code ... if does not work .. attach a zipped copy for us to check and see if if works on other machines.

HTH
RDH
 
I once got a joke email that opened the cd. The joke was that for being a loyal Coke customer you could get a cup holder (so you assume a coolie). Click on the button to get it. Then the tray popped open. I'll look around to see if I still have it somewhere as there might be a good alternative code sample to use from there as well.
 
Stupid question but I have a CD-RW drive as well as a CD Audio drive. I can get this code to open the CD Audio, but can't find the correct wording to have it open the RW drive which would be the one I'd want to have open.

Thanks,

Tim Wright
 
Great those websites have totally changed...FARK.

I should of known I remember the guy running the vbapi site said he was gonna call it quits on hosting that site.

Ill search around...
Jon
 
Here is the old Coca~Cola "free gift" program that Autoeng mentioned. It is only five years old. I do not have VB at home so I do not know if the code can be extracted from the program.
The file was barely to big to post here so I did a Google search and here is the first valid link I found. CokeGift.exe

Also, here is a great Visual Basic site that I have used code for VB & Access 97...
VBnet Visual Basic Developers Resource Centre

HTH
 
Here is a simple example that includes the code I posted.

It only opens and close the CD drawer.
 

Attachments

It's no longer being updated but this site contans the API details: All API
 
Did you ever solve how to open the CD-RW as well as the CD?
I've got the same set up and would love to know the code.
 

Users who are viewing this thread

Back
Top Bottom