Jun 3, 2014 at 2:18am Jun 3, 2014 at 2:18am UTC
I tried lots of ways, but none of them worked.
Jun 3, 2014 at 2:34am Jun 3, 2014 at 2:34am UTC
@BobTheZealotIsEpic
Try this then. And make sure that 'a.wav' is in the same directory as this program, or change the name to point to where it's located.
IE:
std::wstring soundfile(L"C:\\Temp\\a.wav" );
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// PlaySound.cpp : main project file.
#include <iostream>
#include <windows.h>
#include <string>
#pragma comment(lib, "winmm.lib")
int main()
{
std::wstring soundfile(L"a.wav" );
PlaySound(soundfile.c_str(), NULL, SND_ASYNC);
Sleep(2500);
std::cout << "Press any key to close program.." << std::endl;
getchar();
return 0;
}
Last edited on Jun 3, 2014 at 2:39am Jun 3, 2014 at 2:39am UTC
Jun 3, 2014 at 3:12am Jun 3, 2014 at 3:12am UTC
@whitenite1
Does the same directory mean I'm supposed to put the wav file in the project folder?
Jun 3, 2014 at 3:32am Jun 3, 2014 at 3:32am UTC
@whitenite1
How should I change the name to point to where it's located?
Jun 3, 2014 at 3:36am Jun 3, 2014 at 3:36am UTC
@BobTheZealotIsEpic
Yep. Unless you want to specify its location. Otherwise, the project directory is the only place your program will look for it.
Jun 3, 2014 at 3:37am Jun 3, 2014 at 3:37am UTC
Ok, thanks. I will do that.
Jun 3, 2014 at 3:43am Jun 3, 2014 at 3:43am UTC
@whitenite1
When I compile your program, it has an error on line 12:
error: cannot convert 'const wchar_t*' to 'LPCSTR {aka const char*}' for argument '1' to 'BOOL PlaySoundA(LPCSTR, HMODULE, DWORD)'
Jun 3, 2014 at 4:07am Jun 3, 2014 at 4:07am UTC
BobTheZealotIsEpic
When I create a program in Visual C++ 12, I start it off as a CLR Console application. I don't know if that makes a difference or not. But then, it compiles and runs, so..
Otherwise, I'm at a loss for an answer. Maybe someone wiser can offer a solution. sorry..
Jun 3, 2014 at 4:25am Jun 3, 2014 at 4:25am UTC
According to MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx
LPCSTR is a pointer to a null-terminated string of constant ANSI (8-bit) characters, which is like
const char *
(and in the error bob posted, it is the same on his compiler).
The L prefix makes the string literal a string of wide characters, so you are essentially doing something akin to:
1 2 3
const wchar_t * wc_str = L"Hello world!" ;
const char * c_str = wc_str;
http://ideone.com/KXKlPO
I think it'll be okay if you don't use the L prefix (or wide characters in general) in this case .
Edit:
Fixed example.
Last edited on Jun 3, 2014 at 4:39am Jun 3, 2014 at 4:39am UTC
Jun 7, 2014 at 5:06am Jun 7, 2014 at 5:06am UTC
I don't get what I'm supposed to do.
Jun 7, 2014 at 10:09am Jun 7, 2014 at 10:09am UTC
Trolling?
Because you made some pointless posts in your other pointless topic, I am not going to apologise if you think I am giving you a hard time.
Jun 7, 2014 at 11:54am Jun 7, 2014 at 11:54am UTC
how is you Hi Script coming along BobTheZealotIsEpic ?
Jun 20, 2014 at 6:29pm Jun 20, 2014 at 6:29pm UTC
Last edited on Jun 20, 2014 at 6:33pm Jun 20, 2014 at 6:33pm UTC