To control an MCI device, you open the device, send the necessary commands to it, and then close the device. The commands can be very similar, even for completely different MCI devices. For example, the following series of MCI commands plays the sixth track of an audio CD by using the command-string interface:
mciSendString("open cdaudio", lpszReturnString,
lstrlen(lpszReturnString), NULL);
mciSendString("set cdaudio time format tmsf", lpszReturnString,
lstrlen(lpszReturnString), NULL);
mciSendString("play cdaudio from 6 to 7", lpszReturnString,
lstrlen(lpszReturnString), NULL);
mciSendString("close cdaudio", lpszReturnString,
lstrlen(lpszReturnString), NULL);
The next example shows a similar series of MCI commands that plays the first 10,000 samples of a waveform-audio file:
mciSendString(
"open c:\mmdata\purplefi.wav type waveaudio alias finch",
lpszReturnString, lstrlen(lpszReturnString), NULL);
mciSendString("set finch time format samples", lpszReturnString,
lstrlen(lpszReturnString), NULL);
mciSendString("play finch from 1 to 10000", lpszReturnString,
lstrlen(lpszReturnString), NULL);
mciSendString("close finch", lpszReturnString,
lstrlen(lpszReturnString), NULL);
These examples illustrate some interesting facts about MCI commands: