scottlandon
asked on
How do you play a wave file with MFC app.
I am trying to play a sound file, tada.wav, when a game finishes and there is a winner. I have tried using sndPlaySound and cannot get it to work. I get a LNK2001 error when the program compiles. The file location is correct...I cannot figure out what the compiler can't find!!!! Please help.
Hi,
Bye the way have you included the winmm.lib in your project settings?
And mmsystem.h in the file using sndPlaySound()?
Abdij
Bye the way have you included the winmm.lib in your project settings?
And mmsystem.h in the file using sndPlaySound()?
Abdij
Please describe the error message.
I think abdij is right.
You need to add the winmm.lib to your project. Just do a right click on your project in the FileView workspace, then select Add Files to Project. Nevigate to the directory that contains the winmm.lib file and click OK. You sound not get the linker error and the sound should play.
If you are using MS VC++ 6.0 and installed in the default directory, the file is in C:\Program Files\Microsoft Visual Studio\VC98\Lib
If you are using MS VC++ 6.0 and installed in the default directory, the file is in C:\Program Files\Microsoft Visual Studio\VC98\Lib
abdij, beat me to it, I was typing while he posted. Sorry about that.
The easiest way:
HINSTANCE Status;
Status = ShellExecute( NULL, "open", "file://c:\\inventory\\hel p\\yoursou ndfile.wav ",
NULL, NULL, SW_HIDE);
if( (int)Status == 0){
MessageBox( "Can't find default wav player", "Help Error", MB_OK | MB_ICONERROR );
}
This will use Windows default WAV player (i.e. MS media player), and make sure that you leave option SW_HIDE - that way player window will not show up.
Hope this helps
HINSTANCE Status;
Status = ShellExecute( NULL, "open", "file://c:\\inventory\\hel
NULL, NULL, SW_HIDE);
if( (int)Status == 0){
MessageBox( "Can't find default wav player", "Help Error", MB_OK | MB_ICONERROR );
}
This will use Windows default WAV player (i.e. MS media player), and make sure that you leave option SW_HIDE - that way player window will not show up.
Hope this helps
Addition:
In my example I used file that resides in folder: c:\inventory\help at my computer.
Of course you'll replace this folder with the actual path of your WAV file.
Don't forget to use the same string formating like this:
"file://c:\\folder\\yourso undfile.wa v"
You may omit the if statement which checks the success of the operation, if you're sure that there is a default WAV player on your system.
Good luck!
In my example I used file that resides in folder: c:\inventory\help at my computer.
Of course you'll replace this folder with the actual path of your WAV file.
Don't forget to use the same string formating like this:
"file://c:\\folder\\yourso
You may omit the if statement which checks the success of the operation, if you're sure that there is a default WAV player on your system.
Good luck!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
how did it go?
Try
http://codeguru.earthweb.com/multimedia/echosound.html.
Hope this helps,
Abdij