| | |
Visual C++ 2008 playing a sound
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 60
Reputation:
Solved Threads: 3
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:
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.
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:
C++ Syntax (Toggle Plain Text)
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.
Last edited by Wiki_Tiki; Jul 23rd, 2008 at 6:38 pm.
It has to do with the way your compiler is interpreting strings (I think it happens when you set the character encoding to unicode instead of multibyte, or something like that).
I think that this:
will work.
I think that this:
C++ Syntax (Toggle Plain Text)
PlaySound((LPCWSTR)"beep.wav", 0, SND_LOOP|SND_ASYNC);
Last edited by CoolGamer48; Jul 23rd, 2008 at 6:44 pm.
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
•
•
Join Date: Jul 2008
Posts: 60
Reputation:
Solved Threads: 3
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?
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? Last edited by Wiki_Tiki; Jul 23rd, 2008 at 8:14 pm.
It isn't bogus crap. Learn to understand it and you'll begin to be able to solve problems on your own, though its understandable that at first you'll have no idea what it means.
The compilers complaining that the function PlaySound is declared somewhere, but it has no implementation. I'm actually not sure why it said it twice. The implementation would either be in the form of a .cpp file, or, in this case, a .lib file.
To fix this you need to link to the .lib winmm.lib. A simple way to do this is to add
in one of your source files.
The compilers complaining that the function PlaySound is declared somewhere, but it has no implementation. I'm actually not sure why it said it twice. The implementation would either be in the form of a .cpp file, or, in this case, a .lib file.
To fix this you need to link to the .lib winmm.lib. A simple way to do this is to add
C++ Syntax (Toggle Plain Text)
#pragma comment(lib,"winmm.lib")
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
![]() |
Other Threads in the C++ Forum
- Previous Thread: Linked Lists using struct
- Next Thread: fibonocci sequence question
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






