C++ 中的 Playsound() 播放 windows 错误声音,我已经包含 winmm.lib

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

我正在尝试在 C++ 中使用 Playsound()。

我查看了所有内容,但总是听到默认的 windows 错误声音。

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

winmm.lib 已在链接器设置中设置。 完整位置和文件名已经过测试。 我正在使用 Code::Blocks 并使用 C++ 14 标准进行编译。

根据 PlaySound() 文档:

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.

仔细检查该文件是否确实存在于您指定的路径中,并且 运行 您的应用程序的用户是否有权访问该文件。