by $mTp (3 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)
Open and close your CDROM using the MCIsendstring API. I saw the program Heresy made, it's good but kind of complicated, newbies might not understand some stuff. I simply resolved the OPEN/CLOSE problem exploiting the Tag property of a command button. It's quite simple and reliable.
API DeclarationsDeclare 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
'create 2 command buttons, call the first one "Open" and the second one "Close"
'create a label
Private Sub Form_Load()
command1.tag = "open"
Private Sub Command1_Click()
If Command1.Tag = "open" Then
retvalue = mciSendString("set CDAudio door open", _
returnstring, 127, 0)
Command1.Tag = "closed"
Else
retvalue = mciSendString("set cdaudio door closed", returnstring, 127, 0)
Command1.Tag = "open"
End If
Label1.Caption = Command1.Tag 'place a label to check to tag property of the command button