码:
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
2Severity 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作为第一个参数传递,该解析为:在非UNICODE构建上为
const char*
,在UNICODE one上为const wchar_t*
。因此,由于存在一些错误,因此您必须使用UNICODE构建,而应该使用std::wstring
。