# WAV Playback

This topic is 4587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im having trouble playing a wav file in my game. I put the wavs in the resource file as so:- BackMsc WAVE gamemusic.wav PaddleSnd WAVE paddle.wav BlockSnd WAVE block.wav and included the resource.rc and then tried to play the sound as so:- // play the paddle sound ( i hope) PlaySound ("PaddleSnd", hinstance, SND_ASYNC | SND_RESOURCE); and get the following error:- error C2065: 'hinstance' : undeclared identifier. any ideas? thanks chris

##### Share on other sites
C/C++ is case sensitive, I suspect that the identifier is supposed to be hInstance instead of hinstance (if you've used the Windows project wizard).

##### Share on other sites
sadly this didnt work but thanks anyway

##### Share on other sites
Firstly, is hinstance defined?

If you can't easily get a valid HINSTANCE to the function, call
GetModuleHandle( 0 )
Casting the HMODULE return value to an HINSTANCE. (consult MSDN to see why this works)

Secondly, I assume from the error code that you are using Visual C++. In which case, it generally gives resources integer ids instead of string ones. If this is the case, passing "PaddleSnd" won't work as PaddleSnd is actually an integral constant. Passing MAKEINTRESOURCE( PaddleSnd ) will convert the constant value to the appropriate string value.

##### Share on other sites
OK I went down the ID route so

RESOURCE.H :-

# define SOUND_ID_MUSIC 2
# define SOUND_ID_BLOCK 3

RESOURCE.rc:-

#include "RESOURCE.H"

SOUND_ID_MUSIC WAVE music.wav
SOUND_ID_BLOCK WAVE block.wav

All wavs are in working folder , the code is as follows now:-

SND_ASYNC | SND_RESOURCE);

but im getting this:-

error C2065: 'SOUND_ID_PADDLE' : undeclared identifier
error C2065: 'hinstance' : undeclared identifier

I need to declare hinstance in the globals?? how would I do this? Im sorry for being a pain but I had to stop using VB because I found it very boring.

thanks for you attention
chris

##### Share on other sites
PlaySound( MAKEINTRESOURCE( IDR_WAVE1 ), GetModuleHandle( 0 ), SND_RESOURCE );

Replace IDR_WAVE1 with the id of your wave resource.

Ensure that you have #included resource.h in both the resource file itself (the .rc file) and your source file which calls the function. (The .c/.cpp file)

You can use ResHack from http://www.angusj.com/resourcehacker/ to look inside your exe file and see if the resource has actually been included.

(Obviously, include the SND_ASYNC flag if you want asyncronous playback)

##### Share on other sites
Thank you soooooooooo much zoggo!