sndPlaySound

Syntax

BOOL sndPlaySound(lpszSoundName, wFlags)

This function plays a waveform sound specified by a filename or by an entry in the [sounds] section of WIN.INI. If the sound can't be found, it plays the default sound specified by the SystemDefault entry in the [sounds] section of WIN.INI. If there is no SystemDefault entry or if the default sound can't be found, the function makes no sound and returns FALSE.

Parameters

LPSTR lpszSoundName

Specifies the name of the sound to play. The function searches the [sounds] section of WIN.INI for an entry with this name and plays the associated waveform file. If no entry by this name exists, then it assumes the name is the name of a waveform file. If this parameter is NULL, any currently playing sound is stopped.

WORD wFlags

Specifies options for playing the sound using one or more of the following flags:

SND_SYNC

The sound is played synchronously and the function does not return until the sound ends.

SND_ASYNC

The sound is played asynchronously and the function returns immediately after beginning the sound. To terminate an asynchronously-played sound, call sndPlaySound with lpszSoundName set to NULL.

SND_NODEFAULT

If the sound can't be found, the function returns silently without playing the default sound.

SND_MEMORY

The parameter specified by lpszSoundName points to an in-memory image of a waveform sound.

SND_LOOP

The sound will continue to play repeatedly until sndPlaySound is called again with the lpszSoundName parameter set to NULL. You must also specify the SND_ASYNC flag to loop sounds.

SND_NOSTOP

If a sound is currently playing, the function will immediately return FALSE without playing the requested sound.

Return Value

Returns TRUE if the sound is played, otherwise returns FALSE.

Comments

The sound must fit in available physical memory and be playable by an installed waveform audio device driver. The directories searched for sound files are, in order: the current directory; the Windows directory; the Windows system directory; the directories listed in the PATH environment variable; the list of directories mapped in a network. See the Windows OpenFile function for more information about the directory search order.

If you specify the SND_MEMORY flag, lpszSoundName must point to an in-memory image of a waveform sound. If the sound is stored as a resource, use LoadResource and LockResource to load and lock the resource and get a pointer to it. If the sound is not a resource, you must use GlobalAlloc with the GMEM_MOVEABLE and GMEM_SHARE flags set and then GlobalLock to allocate and lock memory for the sound.

See Also

MessageBeep