Problem with playing sound

Hello. (I posted on the wrong forum before I think..)

I am using PlaySound to play a .wav file (1 sec long), but it is failing. The file is located here:

C:\BLACKJACK\welcome.wav

This .wav file is located in the same folder as the .cpp, .h and .dev files

This is my program:
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include <cstdlib>
#include <iostream>
#include "gfx.h"

using namespace std;

int main(int argc, char *argv[])
{
    welcome();
    system("PAUSE");
    return EXIT_SUCCESS;
}


gfx.cpp (PlaySound is in here)
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <windows.h>
#include "gfx.h"
using namespace std;

void welcome() {
     PlaySound ("welcome.wav",NULL,SND_FILENAME|SND_ASYNC);
     cout << " /-------------\ \n";
     cout << "  W E L C O M E \n";
     cout << " \--------------/ \n";

}



gfx.h
1
2
3
4
5
6
#ifndef gfx_h
#define gfx_h

void welcome();

#endif 

(I have no more files as .h or .cpp)

Any help appreciated!


/edit

The error log:
9:14 C:\BLACKJACK\gfx.cpp [Warning] '\040'
11:14 C:\BLACKJACK\gfx.cpp [Warning] unknown escape sequence '\-'
[Linker error] undefined reference to `PlaySoundA@12'
11:14 C:\BLACKJACK\gfx.cpp ld returned 1 exit status
C:\BLACKJACK\Makefile.win [Build Error] [blackjack.exe] Error 1




/edit2

Solved.

You enter:
-lwinmm

in compiler options -> "add these commands to the linker command line"
if you are using dev c++
Last edited on
Regarding your warning:
11:14 C:\BLACKJACK\gfx.cpp [Warning] unknown escape sequence '\-'

Replace line 10 with: cout << " \\--------------/ \n";

The double \\ means that you are not trying to do a command like \n (newline) \t (tab), \0 (terminate) \" (quote) or any others.
Thanks Stewbond!
I was actually also wondering about that :)
Topic archived. No new replies allowed.