Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C++
 switch (LOWORD (wParam))
 {
	case IDC_PLAY:
	static char textmessage[256];
	SendMessage((HWND)lParam,WM_GETTEXT,(WPARAM)256,(LPARAM)textmessage);				
					
	if( strncmp(textmessage, "Play", 4)==0)
	{
	    PlaySoundW(L"C:\Users\Chaiein\Downloads\oscilloscope_src\sound1.wav",NULL, SND_FILENAME);
	    SetWindowText((HWND)lParam,"Stop");
	}
		.....
}		


I am not getting the music that in sound1.wav even if I give full path how to make it work?
Posted
Updated 9-May-12 23:43pm
v3

1 solution

The problem is with your filename. The compiler is using the single \ as the start of escape sequences. You know, just like you use \n as the escape sequence for a newline.

The solution is to either
  • Make them all \\ instead of \
  • Make them all / instead of \
 
Share this answer
 
Comments
chaiein 10-May-12 3:34am    
I used
PlaySoundW(L"C://Users//Chaiein/Downloads/oscilloscope_src//sound1.wav",NULL, SND_FILENAME); still it doesn't work
enhzflep 10-May-12 3:37am    
Nope. It wouldn't. Use this:
PlaySoundW(L"C:/Users/Chaiein/Downloads/oscilloscope_src/sound1.wav",NULL, SND_FILENAME);
PlaySoundW(L"C:\\Users\\Chaiein\\Downloads\\oscilloscope_src\\sound1.wav",NULL, SND_FILENAME);

I.e - you should use either / or \\
Anything else is junk. :)
chaiein 10-May-12 5:31am    
I used PlaySound("sound1.wav",NULL,SND_FILENAME); It worked but with my project which was developed in mfc but not in win32 application. Should I use different command for playing sound in win32.
Code-o-mat 10-May-12 6:07am    
How does it "not work"? It does not compile? It does not get linked? It does not play the sound? It crashes?
stib_markc 10-May-12 6:34am    
Should use double-backslash in the file path when giving file name through code eg: L"C:\\Voice\\wave\\sample.wav"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900