View Full Version : PlaySound in XP
I am converting some programs from 16 bit to 32 bit. In 16 bit I used sndPlaySound. When I tried it in 32 bit, it did not work, so I tried PlaySound. The problem I'm having is that both functions work fine in Windows 95, but when I test it on Windows XP, it will skip playing a sound from time to time... but only on Windows XP. I can get it to work consistently if I load the sound file (.wav) from an external file, but if I try to load it from a resource, it will not play consistently (on XP only). I would prefer to load the sounds from a resource instead of an external file.
Does anyone know why PlaySound does not work well in XP. Is there some other function I should be using?
Any help would be GREATLY appreciated.
patrox
08-21-2003, 11:44 PM
try calling
PlaySound( NULL , NULL ,0 ) ;
just before you play your sound, that'll clear the 'sound channel' ( there might be some silence being played ? )
pat.
Thanks for responding. I did try the PlaySound( NULL , NULL ,0 ), but got the same result. What I finally figured out is that it is a problem with three of my .wav files. I have used them for years in a 16 bit program, but for some reason when I use them in the 32 bit program in Windows XP (they work fine in 9x), they only play once or not at all. They will play if I load them from external files, but not as a resource.
I'm currently looking into the files and trying to figure out why XP does not like these files (at least when they are in a resource). If nothing else, I'll make new files.
Thanks again the PlaySound( NULL , NULL ,0 ) suggestion.
patrox
08-22-2003, 05:50 AM
have you tried the waveOut commands ?
pat.
patrox
08-22-2003, 05:58 AM
another possibility :
sndPlaySound with SND_MEMORY flag.
HRSRC hrSnd = FindResource( gInst , "superSOUND" , "YOURTYPE" ) ;
HGLOBAL hgSound = (HGLOBAL)LoadResource( gInst , hrSnd ) ;
wavePtr = LockResource( hgSound ) ;
sndPlaySound ( wavePtr , SND_MEMORY | SND_ASYNC ) ;
free all the memory stuff and handles and blablabla.
pat.
patrox
08-22-2003, 06:23 AM
When you call PlaySound with a resource, are you sure to give the right instance ( are you sounds in the EXE or in an exernal DLL ? )
pat.
I got it fixed. I resaved the files and now it works fine. I haven't a clue as to why. But, for now, fixed.
Thanks again.