gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 11:26:02 33 4
gpt4 key购买 nike

代码:

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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com