代码:
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/