How to use the mci

The MCI or MediaControlInterface allows you to play and record wave files, play cd´s and midi-files and a lot more!
If you use vb3 or the 16bit version of vb4, please use the 16bit code, otherwise use the 32bit code.

Select the following code with the mouse and copy it into the general section of a form or module.

---16bit code begins here---

Declare Function mcisendstring Lib "MMSystem" (ByVal CommandStr$, ByVal ReturnStr$, ByVal ReturnLen%, ByVal hWndCallback%) As Long

---code ends here---

---32bit code begins here---

Public 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

---code ends here---

Common function:

---code begins here---

Function MCISimpleCommand (CommandStr$) As Long

Dim MCISendTest As Long
Dim MCISendRet As String * 255
MCISendTest = mcisendstring(CommandStr$, MCISendRet, 255, 0)

If (Len(MCISendRet) = 0) Then
MCISendRet = "no return text"
End If
temp$ = MCISendRet

MCISimpleCommand = MCISendTest

End Function

---code ends here---

Use the following code to send commands to the mci:

---bit code begins here---

Dim ret As Long
ret = MCISimpleCommand("insert command here")

---code ends here---

Examples for mci-commands:
MCISimpleCommand "OPEN music.mid type sequencer alias MID"
MCISimpleCommand "PLAY MID"

You can find a complete listing of the mci-commands in the visual basic help.

Go back to my vb-page.