944,196 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 14174
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 29th, 2004
0

can't play wav sound...

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

[PHP]#include <windows.h>
#include <mmsystem.h>

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kakilang is offline Offline
22 posts
since Oct 2004
Oct 29th, 2004
0

Re: can't play wav sound...

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!
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 29th, 2004
0

Re: can't play wav sound...

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 29th, 2004
0

Re: can't play wav sound...

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.
C++ Syntax (Toggle Plain Text)
  1. PlayWav("chimes.wav")
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 29th, 2004
0

Re: can't play wav sound...

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 <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;
}[/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??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kakilang is offline Offline
22 posts
since Oct 2004
Oct 30th, 2004
0

Re: can't play 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??
http://msdn.microsoft.com/library/de..._win32_mci.asp
Knock yourself out.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 30th, 2004
0

Re: can't play wav sound...

thx for helps
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kakilang is offline Offline
22 posts
since Oct 2004
Nov 21st, 2004
-1

Re: can't play wav sound...

Bump Bump Bump
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kakilang is offline Offline
22 posts
since Oct 2004
Nov 21st, 2004
0

Re: can't play wav sound...

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.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Jun 21st, 2005
0

Re: can't play wav sound...

Quote originally posted by kakilang ...
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 <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;
}[/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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bballmitch is offline Offline
10 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Masking a telephone directory
Next Thread in C++ Forum Timeline: Help with mmap





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC