Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

What is wrong with PlaySound() fnc?

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
prompt
Asked:
prompt
  • 4
  • 3
  • 2
1 Solution
 
promptAuthor Commented:
I use Windows 98 and VC++6 compiler.
prompt
0
 
zingoCommented:
What are the errors?

Are you including the windows.h file?
0
 
promptAuthor Commented:
Can I include windows.h without including mmsystem.h?
I set the PlaySound() into int main() fnc. Is it wrong?
prompt
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CSuvendraCommented:

#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
 
zingoCommented:
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
 
promptAuthor Commented:
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
 
CSuvendraCommented:
zingo,

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

<Both headers are not required. mmsystem.h is already included in Windows.h :-)>
0
 
zingoCommented:
Ahh, off course.

Prompt, give the points to CSuvendra, he was faster than me.
0
 
promptAuthor Commented:
Zingo, next time you'll have the points.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now