If you want to use LPCTSTR, then:
LPCTSTR t = _T( "Error.wav");
If you want to use L, then:
LPCWSTR t = L"Error.wav";
PlaySoundW(t, . . .);
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I wanna add some sounds in my programme,so I used the "PlaySound".
But the problem is this.
(I include the"windows.h".
I use MinGW64)
And then it says "cannot convert 'const wchar_t*' to 'LPCTSTR {aka const char*}' in initialization".
I used many ways to try working out the problem,but they didn't work at all!
I just wanna hear the Error sound.
(Hope you can understand my words,thank you!!!)
ADD:
OK.
I have tried all way.
And if there's no any Error,it won't a EXE FILE there(???
So I use cmd to compile the CPP FILE,it says"undefined reference to `PlaySoundA@12"'.
WHAT IS THIS????I HAVEN'T SEEN!!!
Supplement:
I use vscode and I don't know how to check my Character Set.
I use the GNU gdb (GDB) 7.6.1 from MinGW64 to run.
When I install MinGW,I just click this button:
and I do nothing to it.
If you want to use LPCTSTR, then:
LPCTSTR t = _T( "Error.wav");
If you want to use L, then:
LPCWSTR t = L"Error.wav";
PlaySoundW(t, . . .);
You should use Unicode in your project :
Did you try it without the "L" prefix?
If so, what happened?
In VS (2017) the following compiles and links
just fine when UNICODE is not defined.
#include <windows.h>
int main()
{
LPCTSTR t = "error.wav";
PlaySound(t, NULL, SND_FILENAME | SND_ASYNC);
}
With Winmm.lib added to the linker Input as an
Additional Dependency in the project properties.
If UNICODE is defined, this compiles and links
just fine.
#include <windows.h>
int main()
{
LPCTSTR t = L"error.wav";
PlaySound(t, NULL, SND_FILENAME | SND_ASYNC);
}
I think your project's Character Set is "Use Multi-Byte Character Set" or "Not Set".
Just use Preprocessor directives
#ifdef UNICODE
LPCTSTR sz = L"AAA";
#else
LPCTSTR sz = "AAA";
#endif
PlaySound(sz, NULL, SND_FILENAME);