Playing wav files using sndPlaySound or PlaySound

This is how I did it, I used sndPlaySound(filename, SND_SYNC |SND_LOOP) or PlaySound(filename, NULL, SND_SYNC|SND_LOOP) to play a .wav file but however I got a linking error message which says "unresolved external symbol". I've also included "mmsystem.h" header file. How can I solve the problem? What's the difference between sndPlaySound and PlaySound? Is it true that PlaySound can play a .wav from a resource while sndPlaySound can't?
Who is Participating?
Answers2000Connect With a Mentor Commented:
1. To play a .WAV file

PlaySound( "file.wav", NULL, SND_FILENAME ) ;
sndPlaySound( "file.wav", 0 ) ;

for file name make sure you specify the full path.  If you use \ in string literals, then make sure you escape it
"C:\\WINDOWS\\file.wav"  in C, means "C:\WINDOWS\file.wav" in DOS

2. To play from resources

i. Insert a .wav file into your resources
- Go to resource tree on workspace
- Right click
- Pick "Import..."
- Browse the WAV file
- Assign an arbitary id, e.g. "IDC_WAVE"

ii. Play the wave file with
PlaySound( MAKEINTRESOURCE(IDC_WAVE),  AfxGetResourceHandle(), SND_RESOURCE ) ;

1. Fix Unresolved external - link WINMM.LIB (to see this in help click Quick Info button when you see tha API call)

2. sndPlaySound plays a system sound (see WIN.INI or registry) or a file, PlaySound can do either or play a sound in your app's resources.  Otherwise not much difference.  There is often more than 1 way to do the same thing in Windows.

3. PlaySound can play from resource.  sndPlaySound can't.  If you look at parameters, this is obvious as sndPlay sound doesn't include an instance or module handle parameter.  Windows API functions accessing resources usually (always ?) have this as a paramter, e.g. LoadBitmap, LoadString, etc.
thankyouallAuthor Commented:
How can I link my program with WINMM.LIB?
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

thankyouallAuthor Commented:
okay, I've managed to link it with WINMM.LIB, the error message is gone but I still can't hear the sound. I would like to play a non-system wav sound, can it be done using sndPlaySound or PlaySound? Please help.
thankyouallAuthor Commented:
Okie thanks... I'll try it out! :)
thankyouallAuthor Commented:
It works! Thanks for your help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.