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

can't play wav sound...

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

[PHP]#include
#include

int main()
{

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

}[/PHP]

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

kakilang
Newbie Poster
22 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

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!

vegaseat
DaniWeb's Hypocrite
Moderator
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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
DaniWeb's Hypocrite
Moderator
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416
 

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

[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]

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??

kakilang
Newbie Poster
22 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

>Does anyone know how to modify above source code in order to play Windows Media File or play bigger size of the wav file??
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_mci.asp
Knock yourself out. :)

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

thx for helps

kakilang
Newbie Poster
22 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

Bump Bump Bump

kakilang
Newbie Poster
22 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

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
DaniWeb's Hypocrite
Moderator
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416
 

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

[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]

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.

bballmitch
Newbie Poster
10 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

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

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

vegaseat
DaniWeb's Hypocrite
Moderator
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416
 

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.

bballmitch
Newbie Poster
10 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

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);
}
WormNut
Newbie Poster
1 post since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

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

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

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

[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]

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?

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

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

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

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You