MCI Supports Multiple CD-ROMs

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 LongPrivate 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 LongPrivate 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) & ":") = _			DRIVE_CDROM Then			List1.AddItem Chr$(k) & ":"		End If	NextEnd 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, 0End Sub
See also  Is Machine Learning Automating Creativity in Graphic Design?

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist