在我的代码之前,我有这样的代码:
PlaySound(TEXT("MAINTHEME.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
我想再次使用PlaySound,除了这次使用string作为名称。 像这样的东西:
PlaySound((wavid), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
wavid是一个string
但是,正如你们有经验的人所知道的那样,这是行不通的。 我已经尝试了许多不同的语法组合。 但是,似乎没有任何工作。
编辑
新代码:
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
播放声音功能签名是:
BOOL PlaySound( LPCTSTR pszSound, HMODULE hmod, DWORD fdwSound );
所以你需要传递LPCTSTR作为第一个参数,这将解析为:在非UNICODE构建的const char*
,并在UNICODE一个const wchar_t*
。 所以,因为你有一些错误,你必须在UNICODE构建,而你应该使用std::wstring
。