Loading wav files in memory for Win API function PlaySound

Started by
2 comments, last by thijsjellema 22 years, 6 months ago
Hello! I try to make windows play a wav files when a button is pressed in my win32 api program. I found out that a way to play wav files with the windows API is to use the function PlaySound. I found out how to use it, but i can''t find a way to load wav files in memory and play them with this function. Can perhaps anyone helpme with this problem? Thank you very much! Thijs Jellema To_Thijs@Hotmail.Com
Advertisement
Hi
Man this is very easy, allocate a buffer with the size of your wave file and pass the pointer to this buffer to that API function. Nothing special

--Ali Seyedof
http://www.geocities.com/seyedof
--MFC (The Matrix Foundation Crew)
I don''t think you need to load the .wav file in memory yourself to use this function. You just need to specify the name of the file and how you want it to be played.

PlaySound ("sample.wav", NULL, SND_FILENAME | SND_ASYNC);

You can look up in the MSDN all the choices for the third parameter. The third parameter here just says that the first parameter is a filename and the function should return after the sound begins.

Include winmm.lib in your project options.
Hi
No! if you read msdn carefully youll find that the usage first parameter pszSound depends on flags specified. What you posted is the way to play a sound from a wave file not from memory, obviously playing from memory in much faster.

Inorder to play from memory (not file) you must load the wave file into some memory and pass the pointer to this buffer to PlaySound as the first parameter, your flags must contain
SND_MEMORY instead of SND_FILENAME.

--Ali Seyedof
http://www.geocities.com/seyedof
--MFC (The Matrix Foundation Crew)

This topic is closed to new replies.

Advertisement