|
-
Sep 5th, 2002, 03:00 PM
#1
Thread Starter
New Member
-
Sep 5th, 2002, 03:22 PM
#2
Frenzied Member
Code:
i=PlaySound ("C:\\WINDOWS\\MEDIA\\TADA.WAV", 0L,SND_FILENAME | SND_ASYNC);
be sure to include windows.h
-
Sep 5th, 2002, 03:30 PM
#3
Thread Starter
New Member
Thanks for the code, but I'm new to c++ and get 4 error messages, saying undeclared indentifier.
Would I need to declare them as variables, if so how
Thanks
Ilia
-
Sep 5th, 2002, 05:10 PM
#4
Monday Morning Lunatic
Did you #include <windows.h> ?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 5th, 2002, 05:11 PM
#5
Lively Member
Your four errors are probably: i, PlaySound, SND_FILENAME, and SND_ASYNC. Here is the complete code that will do this:
PHP Code:
#include <iostream.h>
#include <windows.h>
int main()
{
bool i;
i=PlaySound("C:\\WINDOWS\\MEDIA\\TADA.WAV", 0L,SND_FILENAME | SND_ASYNC);
}
That should work. Be sure to set your project as a console app.
-
Sep 5th, 2002, 05:13 PM
#6
Monday Morning Lunatic
Two things...
1. iostreams are unnecessary in that program, since it doesn't produce any output.
2. It's <iostream> not <iostream.h>, you've picked the old non-standard header.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 5th, 2002, 05:17 PM
#7
Lively Member
-
Sep 5th, 2002, 05:26 PM
#8
Monday Morning Lunatic
No need
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 6th, 2002, 03:11 PM
#9
Thread Starter
New Member
The code works better but I still get this error message:
--------------------Configuration: sound1 - Win32 Debug--------------------
Compiling...
sound1.cpp
E:\C++\Day5\sound1\sound1.cpp(16) : error C2731: 'main' : function cannot be overloaded
E:\C++\Day5\sound1\sound1.cpp(15) : see declaration of 'main'
E:\C++\Day5\sound1\sound1.cpp(18) : warning C4129: 'W' : unrecognized character escape sequence
E:\C++\Day5\sound1\sound1.cpp(18) : warning C4129: 'M' : unrecognized character escape sequence
E:\C++\Day5\sound1\sound1.cpp(18) : warning C4129: 'T' : unrecognized character escape sequence
E:\C++\Day5\sound1\sound1.cpp(18) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
E:\C++\Day5\sound1\sound1.cpp(19) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.
sound1.exe - 1 error(s), 5 warning(s)
Last edited by ilia-c++; Sep 6th, 2002 at 03:14 PM.
-
Sep 6th, 2002, 03:37 PM
#10
Monday Morning Lunatic
Can you post your entire code, please?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 6th, 2002, 03:55 PM
#11
Thread Starter
New Member
// sound.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main(int argc, char* argv[])
{
return 0;
}
#include <windows.h>
int main()
{
bool i;
i=PlaySound("C:\WINDOWS\MEDIA\TADA.WAV", 0L,SND_FILENAME | SND_ASYNC);
}
-
Sep 6th, 2002, 04:57 PM
#12
Monday Morning Lunatic
You're not allowed two versions of main(). Use just the second half (from #include <windows.h>).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 8th, 2002, 02:58 AM
#13
Frenzied Member
You also need to use double backslashes to avoid the character escape sequence errors.
...and 0L is redundant.
Code:
#include <windows.h>
void main(){
bool i;
i = PlaySound("C:\\WINDOWS\\MEDIA\\TADA.WAV", 0, SND_FILENAME | SND_ASYNC);
}
-
Sep 9th, 2002, 05:58 AM
#14
Also, PlaySound returns a BOOL which is just a synonym for int and not the same as bool.
And in this case, you can simply forget the return value of PlaySound.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|