Solved

What is wrong with PlaySound() fnc?

Posted on 2002-04-30
9
273 Views
Last Modified: 2010-04-02
I want to include a sound file (.wav)  in my console program and
 as I understood I have to use the PlaySound() fnc and to include
Mmsystem.h header file but when I try to compile the program I give a message which tells me
there are 2 errors in the 113 line of the  mmsystem.h file. What shall I do?
Thanks
prompt
0
Comment
Question by:prompt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 

Author Comment

by:prompt
ID: 6980135
I use Windows 98 and VC++6 compiler.
prompt
0
 

Expert Comment

by:zingo
ID: 6980153
What are the errors?

Are you including the windows.h file?
0
 

Author Comment

by:prompt
ID: 6980186
Can I include windows.h without including mmsystem.h?
I set the PlaySound() into int main() fnc. Is it wrong?
prompt
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:CSuvendra
ID: 6980219

#include <windows.h>

int main(int argc, char* argv[])
{
     PlaySound("c:\\chord.wav", NULL, SND_ASYNC | SND_NODEFAULT);
     return 0;
}

In Project->Settings->Library Modules add 'winmm.lib'
0
 

Expert Comment

by:zingo
ID: 6980223
Nop.

I use Visual Studio 6.0 and create a "Win32 Console Application".

Then I edit the main function so it look like this:

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

int main(int argc, char* argv[])
{
     printf("TADA!\n");

  PlaySound("C:\\WINNT\\Media\\tada.wav", NULL, SND_FILENAME);

     return 0;
}

Then modify the project settings so it links with the winmm.lib library.

Works just fine!
0
 

Author Comment

by:prompt
ID: 6980354
You both gave me very good advices but how can I share the points?
I will think it over. Thank you very much!
prompt
Tell me if you have some suggestions.
0
 
LVL 2

Accepted Solution

by:
CSuvendra earned 200 total points
ID: 6982788
zingo,

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

<Both headers are not required. mmsystem.h is already included in Windows.h :-)>
0
 

Expert Comment

by:zingo
ID: 6982983
Ahh, off course.

Prompt, give the points to CSuvendra, he was faster than me.
0
 

Author Comment

by:prompt
ID: 6993217
Zingo, next time you'll have the points.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question