Click here to Skip to main content
13,005,933 members (86,532 online)
Rate this:
Please Sign up or sign in to vote.
 switch (LOWORD (wParam))
	case IDC_PLAY:
	static char textmessage[256];
	if( strncmp(textmessage, "Play", 4)==0)
	    PlaySoundW(L"C:\Users\Chaiein\Downloads\oscilloscope_src\sound1.wav",NULL, SND_FILENAME);

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 19:18pm
Updated 9-May-12 23:43pm

1 solution

Rate this: bad
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 \
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"
chaiein 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170628.1 | Last Updated 10 May 2012
Copyright © CodeProject, 1999-2017
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