c++ - 如何在 PlaySound 中将字符串作为 WAV 的名称传递?

标签 c++ windows visual-studio

代码:

PlaySound((wavid.c_str()), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);

两个错误:

1

Severity    Code    Description Project File    Line    Suppression State
Error (active)      argument of type "const char *" is incompatible with       parameter of type "LPCWSTR"  The Locksmith   c:\Users\DiMaggio\Documents\Visual Studio 2015\Projects\The Locksmith\The Locksmith\CONMAIN.cpp 148 

2

Severity    Code    Description Project File    Line    Suppression State
Error   C2664   'BOOL PlaySoundW(LPCWSTR,HMODULE,DWORD)': cannot convert     argument 1 from 'const char *' to 'LPCWSTR'    The Locksmith   c:\users\dimaggio\documents\visual studio 2015\projects\the locksmith\the locksmith\conmain.cpp 148 

为什么这个“playSound()”不接受字符串作为参数?

最佳答案

播放声音函数签名为:

BOOL PlaySound(
   LPCTSTR pszSound,
   HMODULE hmod,
   DWORD   fdwSound
);

因此您需要将 LPCTSTR 作为第一个参数传递,这解析为:const char* 在非 UNICODE 构建上,在 UNICODE 构建上解析为 const wchar_t*。所以因为你有一些错误,你必须在 UNICODE 构建上,你应该使用 std::wstring 代替。

关于c++ - 如何在 PlaySound 中将字符串作为 WAV 的名称传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36065937/

相关文章:

c++ - 为什么有些词会出现段错误?而其他人似乎工作正常

c++ - MPI_Isend 到非监听进程

windows - 在企业级应用程序上使用 Cygwin

wpf - Visual Studio : How to write Editor Extensions with WPF

visual-studio - Visual Studio 2012 项目文件上的蓝色箭头覆盖

C++ 指针——它们什么时候被重新分配?

node.js - 如何通过终端(ubuntu 或 windows)查找 google chrome 或 firefox tab url?

c++ - 窗口的 C\C++ LINPACK 源代码免费用于商业用途?

asp.net - 使用浏览器链接在 Visual Studio 2015 社区中进行调试时,主页/索引页面自行向下滚动

C++ std::localtime 夏令时规则 (dst) 欧洲与美国