Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 26, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

MCI Supports Multiple CD-ROMs

The Media Control Interface (MCI) can easily support multiple CD audio devices.
You simply specify the drive letter in the MCI open command. To eject the CD from any drive,
first place a listbox on a form. To detect which drives are CD-ROMs,
place this code in the form's General Declarations section:

Private Declare Function GetDriveType Lib _
	"kernel32" Alias "GetDriveTypeA" (ByVal _
	nDrive As String) 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 Const DRIVE_CDROM = 5
The following code in the Form_Load event fills the listbox with available CD-ROM drives.
Note that the code does not detect whether the CD-ROM drive can actually eject the CD.
Use the "capabilities can eject" MCI command to determine that:

Private Sub Form_Load()
	Dim k As Long
	For k = Asc("A") To Asc("Z")
		If GetDriveType(Chr$(k) & ":") = _
			List1.AddItem Chr$(k) & ":"
		End If
End Sub
Place this code in the List1_DblClick event to eject the CD:

Private Sub List1_DblClick()
	mciSendString "open " & _
		List1.List(List1.ListIndex) & _
		" type cdaudio alias cdaudio", _
		vbNullString, 0, 0
	mciSendString "set cdaudio door open", _
		vbNullString, 0, 0
	mciSendString "close cdaudio", vbNullString, _
		0, 0
End Sub
Matt Hart
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date