sound

i am trying to play sound as a test to get the context of sound working to add into other programs but it is giving me a error on the file address.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <Windows.h>
#include <stdio.h>

using namespace std;

int main()
{
	cout << "test sound 1" << endl;
	Sleep(10);
	PlaySound("‪C:\Users\kyle\Music\applause-01.wav", NULL, SND_ASYNC);
}
That is because you are using \ and C++ thinks you are trying to do an escape sequence (like a new line etc).

Either use forward slashes which windows can still read file paths from or use \\ to make it act correctly.
http://en.cppreference.com/w/cpp/language/escape
my error is



1>------ Build started: Project: sound test, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\users\kyle\documents\visual studio 2013\projects\sound test\sound test\source.cpp(11): warning C4566: character represented by universal-character-name '\u202A' cannot be represented in the current code page (1252)
1>c:\users\kyle\documents\visual studio 2013\projects\sound test\sound test\source.cpp(11): error C2664: 'BOOL PlaySoundW(LPCWSTR,HMODULE,DWORD)' : cannot convert argument 1 from 'const char [37]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
http://social.msdn.microsoft.com/Forums/vstudio/en-US/c1b08c0a-a803-41c3-ac8c-84eba3be1ddb/faq-cannot-convert-from-const-char-to-lpctstr

Personally I solve it on VS by doing the first step. (Yours isn't exactly the same error but it's for the same reason).

Change your project configuration to use multibyte strings. Press ALT+F7 to open the properties, and navigate to Configuration Properties > General. Switch Character Set to "Use Multi-Byte Character Set".
Last edited on
Also make sure that your WAVE file is relatively small (say, less than 100 kilobytes):
MSDN wrote:
The sndPlaySound and PlaySound functions load an entire waveform-audio file into memory and, in effect, limit the size of the file they can play. Use sndPlaySound and PlaySound to play waveform-audio files that are small — up to about 100K. These two functions also require the sound data to be in a format that is playable by one of the installed waveform-audio drivers, including the wave mapper.

For larger sound files, use the Media Control Interface (MCI) services. For more information, see MCI.

http://msdn.microsoft.com/en-us/library/windows/desktop/dd798671%28v=vs.85%29.aspx
Topic archived. No new replies allowed.