Jump to content
  • Advertisement
Sign in to follow this  
burgess_1984

WAV Playback

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
OK I went down the ID route so

RESOURCE.H :-

# define SOUND_ID_PADDLE 1
# define SOUND_ID_MUSIC 2
# define SOUND_ID_BLOCK 3

RESOURCE.rc:-

#include "RESOURCE.H"

SOUND_ID_MUSIC WAVE music.wav
SOUND_ID_PADDLE WAVE paddle.wav
SOUND_ID_BLOCK WAVE block.wav

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

PlaySound (MAKEINTRESOURCE (SOUND_ID_PADDLE), hinstance,
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!