Solved

What is wrong with PlaySound() fnc?

Posted on 2002-04-30
9
268 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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.

828 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