Visual C++ 2008 playing a sound
Hi,
I need help playing a sound in Visual C++ 2008. (Windows Forms App). I've tried many things searching on google, I used this method:
PlaySound("beep.wav", 0, SND_LOOP|SND_ASYNC);
Then I get the error, "'PlaySoundW' : cannot convert parameter 1 from 'const char [9]' to 'LPCWSTR''. Can anyone help me play the sound 'beep.wav' that I have in my resources folder? I need it to loop forever, (or 9999999999999999999999 times if u know wut i mean :)).
Thanks in advance to anyone who can help.
Wiki_Tiki
Junior Poster in Training
60 posts since Jul 2008
Reputation Points: 23
Solved Threads: 3
Since you are compiling with the UNICODE flag, you must either indicate that string literals are wide-char directly: L"Hello world!" or (better yet) use theTEXT() macro:
PlaySound(TEXT("beep.wav"), 0, SND_LOOP|SND_ASYNC);
Have fun.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
I forgot to describe at the beginning that this is supposed to loop forever after a timer finishes. Anyway, I get the same 3 errors, using any of your snippets:
1. error LNK2028: unresolved token (0A000011) "extern "C" int __stdcall PlaySoundW(wchar_t const *,struct HINSTANCE__ *,unsigned long)" (?PlaySoundW@@$$J212YGHPB_WPAUHINSTANCE__@@K@Z) referenced in function "private: void __clrcall Timer1::Form1::timer1_Tick(class System::Object ^,class System::EventArgs ^)" (?timer1_Tick@Form1@Timer1@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) Timer.obj
2. error LNK2019: unresolved external symbol "extern "C" int __stdcall PlaySoundW(wchar_t const *,struct HINSTANCE__ *,unsigned long)" (?PlaySoundW@@$$J212YGHPB_WPAUHINSTANCE__@@K@Z) referenced in function "private: void __clrcall Timer1::Form1::timer1_Tick(class System::Object ^,class System::EventArgs ^)" (?timer1_Tick@Form1@Timer1@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) Timer.obj
3. fatal error LNK1120: 2 unresolved externals
Basically, this is one of those times when the compiler seems to output a whole bunch of bogus crap :(. Any Ideas?
Wiki_Tiki
Junior Poster in Training
60 posts since Jul 2008
Reputation Points: 23
Solved Threads: 3
Wow man, thanks a ton. (I know, my questions always sound retarded :()
So simple to add a pragma comment...
Oh well, I'm a complete noob at VC++
But thanks a lot for the help, you were great
Wiki_Tiki
Junior Poster in Training
60 posts since Jul 2008
Reputation Points: 23
Solved Threads: 3