c++ - Playsound() 在 C++ 中播放 Windows 错误声音,我已经包含了 winmm.lib

标签 c++ playsound

我正在尝试在 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.

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

关于c++ - Playsound() 在 C++ 中播放 Windows 错误声音,我已经包含了 winmm.lib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50070188/

相关文章:

c++ - 如何从 vector<string> 中提取第一个元素并在循环中将 vector 大小减少 1

C++ 中 C++ 不区分大小写的计数

c++ - 结合C++问题中的几个基本思想

swift - 如何停用播放声音

c++ - 如何多次使用playsound功能?

c++ - 如何判断当前进程是否为服务(C++、Win32)?

c++ - Windows 特定类型和 native 类型 C++

c++ - 无法使用PlaySound在c++中播放音频文件

c - 我如何设计一个连续播放声音但不阻止程序其余部分的循环?

c++ - 背景音乐和声音