Jump to content
gaby90boy

Control the CD-ROM Door

Recommended Posts

Posted

When your program makes use of the CD-ROM drive, it can be a nice touch to open and close the door under program control. You can do so with the mciSendString function from the Windows API. This function provides a general purpose interface to Windows' multimedia capabilities. Its declaration is shown here:

Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _

(ByVal lpCommandString As String, ByVal lpReturnString As String, _

ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Because the CD-ROM is considered to be a multimedia device, you can use this API function to control it. The first argument tells the device what you want to do. For example, pass the string "set CDAudio door open" to open the door. For example:

retval = mciSendString("set CDAudio door open", "", 0, 0)

You can see that the second through fourth arguments are not used in this case and are passed either a blank string or the value zero. Likewise the function's return value can be ignored. Along with the function declaration shown above you can put the following two procedures in a code module in your program to provide control of the CD-ROM door.

Public Sub OpenCDDoor()

Dim retval As Long

retval = mciSendString("set CDAudio door open", "", 0, 0)

End Sub

Public Sub CloseCDDoor()

Dim retval As Long

retval = mciSendString("set CDAudio door closed", "", 0, 0)

End Sub

Note that calling OpenCDDoor when the door is already open, or CloseCDDoor when it is closed, has no effect.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...