Solved

What is wrong with PlaySound() fnc?

Posted on 2002-04-30
9
263 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
Comment Utility
I use Windows 98 and VC++6 compiler.
prompt
0
 

Expert Comment

by:zingo
Comment Utility
What are the errors?

Are you including the windows.h file?
0
 

Author Comment

by:prompt
Comment Utility
Can I include windows.h without including mmsystem.h?
I set the PlaySound() into int main() fnc. Is it wrong?
prompt
0
 
LVL 2

Expert Comment

by:CSuvendra
Comment Utility

#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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:zingo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ahh, off course.

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

Author Comment

by:prompt
Comment Utility
Zingo, next time you'll have the points.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now