Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Win32 MFC VC9.0 VC VC++
 
 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 9-May-12 20:18pm
chaiein1.8K
Edited 10-May-12 0:43am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 \
  Permalink  
Comments
chaiein at 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 at 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 at 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 at 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 at 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"
chaiein at 10-May-12 7:28am
   
I had made mistake with the wav file because of its name sound1.wav.wav I created new sound1 file problem solved..

PlaySoundW(L"C:\\Users\\Chaiein\\Downloads\\oscilloscope_src - Copy\\sound1.wav",NULL, SND_FILENAME);

Thank you all of you for solution:)

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

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 325
2 Richard MacCutchan 265
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 10 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100