Link to home
Start Free TrialLog in
Avatar of kag0
kag0

asked on

play a wav??

how do I play a wav file in my program??
Avatar of viktornet
viktornet
Flag of United States of America image

Are you using C/C++ Builder???

Regards,
Viktor Ivanov
ASKER CERTIFIED SOLUTION
Avatar of warmcat
warmcat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is actually a Delphi code.....

PlaySound(PChar(ListBox1.Items[ListBox1.ItemIndex]), 0, snd_Async);

which would be something like this in C++ Builder...

PlaySound(PChar(ListBox1->Items[ListBox1->ItemIndex]), 0, snd_Async);

I'm not sure if there is actually a PChar() but you figure it out...

Regards,
Viktor Ivanov
Avatar of kag0
kag0

ASKER

I'm way out of my league here, I hope to understand that answer someday, but for now, I'm lost.
 An example program might put it into perspective for me.I'm using Borland 4.5.  
Avatar of kag0

ASKER

Adjusted points to 100
add a line to your program, along the lines of:

if(PlaySound( "c:\\windows\\media\\ding.wav", NULL, SND_FILENAME)==TRUE) {  // sound played okay

} else {  // trouble

}
   
Regards,

-Andy

Avatar of kag0

ASKER


Compiling SOUNDTRY.CPP:
Error : Call to undefined function 'PlaySound' in function main()
Error: Undefined symbol 'SND_FILENAME' in function main()

void main(void){
if(PlaySound( "c:\\wavefiles\\clay.wav", NULL, SND_FILENAME)==TRUE)
 {}
else{}
}should this work??
 any #includes i should add?
I can't do it.
Avatar of kag0

ASKER

A beginner would know more about this than I do. I'll have to go back and finish learning C first I think. Here's a few extra points
#include <mmsystem.h>

You also need to link with winmm.lib.

Yes, it should work, as chensu says (and I forgot) you do need to include mmsystem.h, which defines PlaySound() and the matching symbols like SND_FILENAME.  Additionally, you need to add winmm.lib to the list of files in your project (at least that's how VC++ works, perhaps Borland requires you to explicitly list it as a library).  Don't worry, you're nearly there.