Export (0) Print
Expand All
Expand Minimize

sndPlaySound function

The sndPlaySound function plays a waveform sound specified either by a file name or by an entry in the registry or the WIN.INI file. This function offers a subset of the functionality of the PlaySound function; sndPlaySound is being maintained for backward compatibility.

Syntax


BOOL sndPlaySound(
   LPCTSTR lpszSound,
   UINT    fuSound
);

Parameters

lpszSound

A string that specifies the sound to play. This parameter can be either an entry in the registry or in WIN.INI that identifies a system sound, or it can be the name of a waveform-audio file. (If the function does not find the entry, the parameter is treated as a file name.) If this parameter is NULL, any currently playing sound is stopped.

fuSound

Flags for playing the sound. The following values are defined.

Value Meaning
SND_ASYNCThe sound is played asynchronously and the function returns immediately after beginning the sound. To terminate an asynchronously played sound, call sndPlaySound with lpszSound set to NULL.
SND_LOOPThe sound plays repeatedly until sndPlaySound is called again with the lpszSound parameter set to NULL. You must also specify the SND_ASYNC flag to loop sounds.
SND_MEMORYThe parameter specified by lpszSound points to an image of a waveform sound in memory.
SND_NODEFAULTIf the sound cannot be found, the function returns silently without playing the default sound.
SND_NOSTOPIf a sound is currently playing in the same process, the function immediately returns FALSE, without playing the requested sound.
SND_SENTRY
Note  Requires Windows Vista or later.
If this flag is set, the function triggers a SoundSentry event when the sound is played. For more information, see PlaySound.
SND_SYNCThe sound is played synchronously and the function does not return until the sound ends.
SND_SYSTEM
Note  Requires Windows Vista or later.
If this flag is set, the sound is assigned to the audio session for system notification sounds. For more information, see PlaySound.

 

Return value

Returns TRUE if successful or FALSE otherwise.

Remarks

If the specified sound cannot be found, sndPlaySound plays the system default sound. If there is no system default entry in the registry or WIN.INI file, or if the default sound cannot be found, the function makes no sound and returns FALSE.

The specified sound must fit in available physical memory and be playable by an installed waveform-audio device driver. If sndPlaySound does not find the sound in the current directory, the function searches for it using the standard directory-search order.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Mmsystem.h (include Windows.h)

Library

Winmm.lib

DLL

Winmm.dll

Unicode and ANSI names

sndPlaySoundW (Unicode) and sndPlaySoundA (ANSI)

See also

Waveform Audio
Waveform Functions
Play Sound

 

 

Community Additions

ADD
Show:
© 2015 Microsoft