-
how to open files
Hello,
I'm trying to open a sound file in c++ and it just doesn't work!, if anyone knows the code for that then can they please send it.:rolleyes:
Also is the code for opening and playing music files (wav) different from the code to open exe files or zip files.
Thanks Ilia:o
-
Code:
i=PlaySound ("C:\\WINDOWS\\MEDIA\\TADA.WAV", 0L,SND_FILENAME | SND_ASYNC);
be sure to include windows.h
-
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:D
Thanks
Ilia:cool:
-
Did you #include <windows.h> ?
-
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.
-
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.
-
-
-
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)
-
Can you post your entire code, please?
-
// 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);
}
-
You're not allowed two versions of main(). Use just the second half (from #include <windows.h>).
-
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);
}
-
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.