Search code examples
c++playsound

Playsound() in C++ playing windows error sound, I have included winmm.lib


I'm trying to use Playsound() in C++.

I've looked at everything but I always get the default windows error sound.

PlaySound(TEXT("D:\\Pokemon Game Stuff\\Programming\\Tests\\city simulator\\Sound.wav"), NULL, SND_FILENAME | SND_ASYNC);

winmm.lib has been set up in linker settings. Full location and just filename has been tested. I'm Using Code::Blocks and compiling with C++ 14 standards.


Solution

  • Per the PlaySound() documentation:

    SND_FILENAME
    The pszSound parameter is a file name. If the file cannot be found, the function plays the default sound unless the SND_NODEFAULT flag is set.

    ...

    PlaySound searches the following directories for sound files: the current directory; the Windows directory; the Windows system directory; directories listed in the PATH environment variable; and the list of directories mapped in a network. If the function cannot find the specified sound and the SND_NODEFAULT flag is not specified, PlaySound uses the default system event sound instead. If the function can find neither the system default entry nor the default sound, it makes no sound and returns FALSE.

    Double check that the file actually exists at the path you are specifying, and that the user that is running your app has permissions to access the file.