below is the source code that i type, but it can't play the wav sound

#include <windows.h>
#include <mmsystem.h>

int main()
{
   
PlaySound("chimes.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
return o;

}

when i compile this source code the compiler prompt link error
can anyone help to show the problem

i using windows xp and dec c++ 4.9.9.0 compiler

Now it gets hairy!

You are talking GUI programming and need to bind with winmm.lib or such, or perhaps load winmm.dll. BCX makes that easy and has a sample! Dev-Cpp has something like like libwinmm.a in the \lib directory. Maybe we have to wait till Narue wakes up, he knows everything and will help you!

>You are talking GUI programming
No, PlaySound isn't a GUI function, but it does require linking with a new library.

>can anyone help to show the problem
You need to link with winmm.lib. IIRC you can go to the Project menu, select Project Options, then in the box titled "Object File or Linker Options" add -lwinmm.lib to the list. I'm fairly certain that the library is available--but not linked--by default for Dev-C++, so after doing this your build should work fine.

If you succeed in DevCpp with this sound project, please post it! By the way, just in case you are curious, this would be the code for BCX, a one liner, short and simple! If you look at the generated C code, it uses PlaySound() from the winmm.dll which is in the Windows\system32\ directory. Compiles to a 24k executable that chimes.

PlayWav("chimes.wav")

Vegaseat and Narue thx for yours help

i succeed play the wav sound Here i will review the step again of how to code a porgram that play wav sound by using Dev-c++ 4.9.9.0

1- create a project file.

2-Choose Console Application in Basic tab.

3-After Create the Project File go to Project Option

4-Choose Parameter tab

5-Click the Add Library or Object

6-Browse the location of Dev-c++ lib and choose the libwinmm

7-click ok and exit the Project Option

8-type the below source code

#include <windows.h>
#include <mmsystem.h>
#include <conio.h>

using namespace std;

int main(int argc, char *argv[])
{
  PlaySound("chimes.wav",NULL,SND_FILENAME|SND_ASYNC);//PLAY WAV SOUND ONCE
  
  //PlaySound("chimes.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
  //ANOTHER OPTION PLAY REPEATED WAV SOUND
  
  getch(); 	
  return 0;
}

then when u run ur program there will be chimes wav sound


Does anyone know how to modify above source code in order to play Windows Media File or play bigger size of the wav file??

thx for helps

kakilang seems to be bored and needs something to chew on. I just threw up a little code snippet called "An AVI Media Player (GUI code for Dev C++)" check it out there.

Vegaseat and Narue thx for yours help

i succeed play the wav sound Here i will review the step again of how to code a porgram that play wav sound by using Dev-c++ 4.9.9.0

1- create a project file.

2-Choose Console Application in Basic tab.

3-After Create the Project File go to Project Option

4-Choose Parameter tab

5-Click the Add Library or Object

6-Browse the location of Dev-c++ lib and choose the libwinmm

7-click ok and exit the Project Option

8-type the below source code

#include <windows.h>
#include <mmsystem.h>
#include <conio.h>

using namespace std;

int main(int argc, char *argv[])
{
  PlaySound("chimes.wav",NULL,SND_FILENAME|SND_ASYNC);//PLAY WAV SOUND ONCE
  
  //PlaySound("chimes.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
  //ANOTHER OPTION PLAY REPEATED WAV SOUND
  
  getch(); 	
  return 0;
}

then when u run ur program there will be chimes wav sound


Does anyone know how to modify above source code in order to play Windows Media File or play bigger size of the wav file??

umm...thats still not working for me. it keeps giving me this error....
C:\Documents and Settings\mitchell\Desktop\Playing sound\Makefile.win [Build Error] [Project1.exe] Error 1
i did EXACTLY what you said and it won't compile. :( any help would be great.

Look at C++ code snippet
http://daniweb.com/code/snippet119.html

Most likely you didn't specify the full path for the .wav file.

dude.....you ROCK....but now how do i make it so it doesn't loop? i want stuff to happen afterwards.

I'm using Microsoft Net 2003 ---

It links, then...

final project error LNK2001: unresolved external symbol "int __stdcall PlaySoundA(char const *,struct HINSTANCE__ *,unsigned long)" (?PlaySoundA@@$$J212YGHPBDPAUHINSTANCE__@@K@Z)


final project fatal error LNK1120: 1 unresolved externals

What? I'm using the following code:

#include <iostream>
#include <windows.h> 
#include <mmsystem.h> 
#include <conio.h> 

int main()
{
         PlaySound("C:\temp\welcome.wav",NULL,SND_FILENAME|SND_ASYNC);
}

Just remove the "using namespace std" and you will see the code just working fine... :)

Vegaseat and Narue thx for yours help

i succeed play the wav sound Here i will review the step again of how to code a porgram that play wav sound by using Dev-c++ 4.9.9.0

1- create a project file.

2-Choose Console Application in Basic tab.

3-After Create the Project File go to Project Option

4-Choose Parameter tab

5-Click the Add Library or Object

6-Browse the location of Dev-c++ lib and choose the libwinmm

7-click ok and exit the Project Option

8-type the below source code

#include <windows.h>
#include <mmsystem.h>
#include <conio.h>

using namespace std;

int main(int argc, char *argv[])
{
  PlaySound("chimes.wav",NULL,SND_FILENAME|SND_ASYNC);//PLAY WAV SOUND ONCE
  
  //PlaySound("chimes.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
  //ANOTHER OPTION PLAY REPEATED WAV SOUND
  
  getch(); 	
  return 0;
}

then when u run ur program there will be chimes wav sound


Does anyone know how to modify above source code in order to play Windows Media File or play bigger size of the wav file??

I did the same and the wav file played (except that I had to comment the using namespace std to make it work).My task is how to make it run as a normal C file not as a project file.Because I have a .C file which is getting run when included in a project.I am getting error "multiple target patterns in make file."And i cudn't make the above sound code just as a C file.Can you please tell me how to solve this?

> Can you please tell me how to solve this?
Perhaps by starting your own thread, and not hijacking some thread over 2 years old.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.