954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Cpp program to play wav ffile (sound)

The following steps tell how to create a project file to play a wav sound file
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

[PHP]#include
#include
#include

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;
}[/PHP]

Now my problem statement is to just create a C or Cpp file to play the wav file by not creating a project.I have tried a lot but couldn't do so.The reason probably might be with adding libwinmm to the program.The above procedure tells about adding it to project but how shall I do the same if I want to play it just in a file.(I mean what about libwinmm)

danibootstrap
Light Poster
46 posts since Dec 2007
Reputation Points: 23
Solved Threads: 0
 

If you're trying to compile this at the command line, then it would be something like
gcc prog.c -lwinmm
where thewinmm specifies the name of the library to link with, in this case libwinmm.a

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

In now solved the prob..basically it was a linker error

danibootstrap
Light Poster
46 posts since Dec 2007
Reputation Points: 23
Solved Threads: 0
 

wow... that really helped me!!
:)
thanks!!!

penguina888
Newbie Poster
1 post since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You