I included a .wav file to the project, made a function declaration for the filename and such, plus flags, included mmsystem.h and used a wParam switch statement under WM_KEYUP case label with a VK_ESCAPE function so when you press escape it will call on the PlaySound function but it just makes an error noise when you play it and fails.

I included a .wav file to the project, made a function declaration for the filename and such, plus flags, included mmsystem.h and used a wParam switch statement under WM_KEYUP case label with a VK_ESCAPE function so when you press escape it will call on the PlaySound function but it just makes an error noise when you play it and fails.

if you want a GOOD FREE OpenSource library to play mp3/wav/ogg/flac then try CAudio hereit already have all dlls and libs, so u don't need to compile any sourcesit's based on popular crossplatform OpenAL and have no problem working with dx, it also has tutorials and memory manageraside from that it can also record sounds from mic, use special effects[reverb, echo, underwater] and stream audio.

now about your problem: PlaySound("blah.wav", NULL, SND_FILENAME);this functions returns true if it can play sound, you need check for that firstpossible reasons for not playing:application seeks that file in debug foler, while it's located somehwere else, try "../blah.wav"it's wrong wav file[since that api can play only spiecific wav files] try different wav file, for example the file that goes with windows

If i am not wrong WM_KEYUP triggers the event when you relese the button( in this case Escape ). You can try to switch to WM_KEYDOWN, which will trigger the events when you press the button.All DirectX APIs for playing sound are deprecated, except XACT, which too is kinda hardcore, so you can switch to what e3d_ALiVE proposed - CAudioor use FMOD , which is superb, but if you are planning to sell your game you have to pay for license.

By the way did you take this source code from tutorial or something?Because playing sound with DirectSound is a lot more complicated:tut

Also in your code you never initialize any sound system, which is like to wanna play dvd, but without dvd player Also why do you declare at top PlaySound? Isnt this function declared in mmsystem.h already?Also i guarantee that with fmod you will play background sound in less then 1 hour.Also i got source code for this if need help with fmod.Zomg too much also.

Try providing the absolute path to the .wav file. The current working directory might not be where you think it is (esp. when running from IDE)

I did provide the absolute path, put it in a search directory, changed the declaration around, everything. A tutorial claimed that you only need to declare a prototype function and then just call on the function and it plays a sound. That's it...But it doesn't work.

I tried everything I can think of. It compiles, everything works fine, but the sound won't play.

Also, I tried those other sound libraries....They were a pain. All they did was cause the compiler to endlessly complain about missing .dll files and it was just torture.

Does the function fail? If so, try checking the result of GetLastError().

Another cause might be a invalid wav file. Just because one player can play it doesn't mean it's a proper file. Check if other players have no problem with the file as well. Sometimes just opening the wave in an audio editor and saving again fixes problems.

So basically there is a class where is all the stuff wrapped for playing sound, loading sound, managind sound and etc.This is sound system and it must be initialized somewhere in your code. Otherwise you cant play anything.Now if you are truly hardcore you can check out the example in DirectX Sample browser about xact.If you are not i again recomment you to look at FMOD.And if you still dont trust me here is link with all commercial games that uses fmod:Link , including crysis zomg.

So basically there is a class where is all the stuff wrapped for playing sound, loading sound, managind sound and etc.This is sound system and it must be initialized somewhere in your code. Otherwise you cant play anything.Now if you are truly hardcore you can check out the example in DirectX Sample browser about xact.If you are not i again recomment you to look at FMOD.And if you still dont trust me here is link with all commercial games that uses fmod:Link , including crysis zomg.

End this topic already!

Okay, I downloaded FMOD because Windows API PlaySound continually fails no matter what.....How do I actually use it? It just installs a folder filled with tons of jibberish FOBJ files and I don't have any idea on what to do next.

I wanted something simple, like with installation as well....Downloading these APIs just makes it even harder because some are just so difficult to even compile/link because the files are disorganized and I have no idea on where to put them, what kind of files does what, etc.

That's why I tried PlaySound on Windows API, but it fails so forget it....

PS: Just so you know I read the documentation and the site and neither offers installation advice.

To add, I'm also very angry and upset and unsatisfied at the help I've been getting here.

I provided the complete code, all-around info, and no help. I've been at this for 3 weeks now and still can't even hear a sound being played in a window, sadly....It really pisses me off and I'm tired of not getting any real help.

PlaySound("C:\\SOUNDS\\BELLS.WAV", NULL, SND_SYNC);
If the specified file does not exist, or if the file does not fit into the available memory, PlaySound plays the default system sound. If no default system sound has been defined, PlaySound fails without producing any sound. If you do not want the default system sound to play, specify the SND_NODEFAULT flag, as shown in the following example:

PlaySound("C:\\SOUNDS\\BELLS.WAV", NULL, SND_SYNC | SND_NODEFAULT);

Try changing the flags you should start with the system sound and see if it beeps. And also the wave file may be to big and it will fail.
I would go for xact

PlaySound("C:\\SOUNDS\\BELLS.WAV", NULL, SND_SYNC); If the specified file does not exist, or if the file does not fit into the available memory, PlaySound plays the default system sound. If no default system sound has been defined, PlaySound fails without producing any sound. If you do not want the default system sound to play, specify the SND_NODEFAULT flag, as shown in the following example:

PlaySound("C:\\SOUNDS\\BELLS.WAV", NULL, SND_SYNC | SND_NODEFAULT);

Try changing the flags you should start with the system sound and see if it beeps. And also the wave file may be to big and it will fail. I would go for xact

I tried...It still doesn't work. It just eithers plays the default noise or no noise at all. And the .wav file I'm using is 1 second or like 4 bytes....It can't be too large.

I changed the flags around, changed the directories, added search directories, etc. It still doesn't play any .wav file and I tried over 16 of them.

And yes, the simple Beep(100,1000) function works, but PlaySound does not.