Solved

What is wrong with PlaySound() fnc?

Posted on 2002-04-30
9
266 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

776 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