Playing wave sounds

Whenever I use PlaySound() I get the error

c:\documents and settings\CPlusPlus\my documents\visual studio 2010\projects\wave\wave\wave.cpp(8): error C2664: 'PlaySoundW' : cannot convert parameter 1 from 'const char [12]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


My cpp code is

1
2
3
4
5
6
7
8
9
10
11
#include "stdafx.h"
#pragma comment(lib, "winmm.lib")

using namespace std;

int main()
{
	PlaySound("MySound.wav", NULL, SND_ASYNC);
	return 0;
}


I include all of the other headers in stdafx.h, and in it is...

1
2
3
4
5
6
7
8
#pragma once

#include "targetver.h"

#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <tchar.h> 


I have no idea what to do, I am COMPLETELY new to including any kind of sound in a program, and I am still pretty newby with anything Win32.
You're using the Unicode version of Windows API functions, so you need to write your strings like this: L"MYSound.wav"
Cool! Okay, that works, and also

PlaySound(TEXT("MySound.wav"), NULL, SND_ASYNC);

Yes! This is great! Thanks for the help! Anybody wanting more reference to the function, just go here.

http://msdn.microsoft.com/en-us/library/dd743680(v=vs.85).aspx
Actually, I have another question, how would I play the sound if it is in a directory, inside the directory the exe is in? Would I have to use a resource file?
Couldn't you just do PlaySound("Dir\\MySound.wav"), NULL, SND_ASYNC)?
I had been trying to include that, but it wasn't working. But actually, I think the problem was I was just putting one '\' and not two.
I can confirm that that is the issue. Adding just one'\'.

'\' is the opening of an escape sequence in c/c++ as well as in many other languages. so '\\' would be the escape sequence for the character '\'
Or just don't use \ at all and use / like you should
Topic archived. No new replies allowed.