Use the MCI_SOUND command to play a sound stored as a WAVE file. MCI_SOUND uses the MCI_SOUND_PARMS parameter block to specify the filename of the WAVE file or the name of an alias defined in the [Sounds] section of WIN.INI. MMSYSTEM.H defines MCI_SOUND_PARMS as follows:
typedef struct {
DWORD dwCallback; /* callback for MCI_NOTIFY flag */
LPSTR lpstrSoundName; /* filename of WAVE file to play */
} MCI_SOUND_PARMS;
The following function plays the sound identified by the lpszSoundName parameter:
/* Plays a given sound using MCI_SOUND. Returns as soon as playback
* begins. Returns 0L on success; otherwise, it returns an MCI error code.
*/
DWORD playWAVESound(LPSTR lpszSoundName)
{
DWORD dwReturn;
MCI_SOUND_PARMS mciSoundParms;
/* Play the given sound. Because there is no device to close,
* don't notify a window or wait for command completion.
*/
mciSoundParms.lpstrSoundName = lpszSoundName;
if (dwReturn = mciSendCommand(NULL, MCI_SOUND, MCI_SOUND_NAME,
(DWORD)(LPVOID) &mciSoundParms))
{
/* Error playing sound, return error code.
*/
return (dwReturn);
}
return (0L);
}
The sound played by MCI_SOUND must fit in available physical memory and be in a data format playable by one of the installed waveform audio device drivers.