Play sound

error which i cant fix

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 4393 Views - Last Post: 21 May 2010 - 09:57 AM Rate Topic: -----

#1 liverpool0912  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 04-June 08

Play sound

Post icon  Posted 26 August 2008 - 05:28 AM

#include <iostream>
#include <windows.h>
#include <mmsystem.h> //Windows multimedia stuff
#include <winbase.h> //defines sleep function
void main(void)
{
char filename[255]="26 - Halo.wav"; //file must be in same directory as executeable

sndPlaySound(filename,SND_LOOP);
//using SND_ASYNC will cause program execution to continue
//using SND_SYNC will cause the program to halt execution until
//the sound is done playing
//using SND_LOOP will cause the sound to play over and over.
//SND_LOOP must be used with SND_SYNC like so,
//sndPlaySound(filename, SND_SYNC | SND_LOOP);;

}




c:\users\liverpool0912\documents\visual studio 2005\projects\fh\fh\fhd.cpp(14) : error C2664: 'sndPlaySoundW' : cannot convert parameter 1 from 'char [255]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

whats the problem

and another question can i use .mp3 files instead of wav files?

Is This A Good Question/Topic? 0
  • +

Replies To: Play sound

#2 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1376
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: Play sound

Posted 26 August 2008 - 06:00 AM

The sndPlaySound function looks for a type LPCWSTR instead of char[]

Try this:
LPCWSTR lpFileName = "26 - Halo.wav"

Hope this helps :)
Was This Post Helpful? 0
  • +
  • -

#3 liverpool0912  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 04-June 08

Re: Play sound

Posted 26 August 2008 - 06:26 AM

#include <iostream>
#include <windows.h>
#include <mmsystem.h> //Windows multimedia stuff
#include <winbase.h> //defines sleep function

// If you get weird link errors, make sure that your compiler knows
// where to find winmm.lib


void main(void)
{

LPCWSTR lpFileName = "26 - Halo.wav";
 //file must be in same directory as executeable

sndPlaySound(filename,SND_LOOP);
//using SND_ASYNC will cause program execution to continue
//using SND_SYNC will cause the program to halt execution until
//the sound is done playing
//using SND_LOOP will cause the sound to play over and over.
//SND_LOOP must be used with SND_SYNC like so,
//sndPlaySound(filename, SND_SYNC | SND_LOOP);;

}



i did what u told me and this is what i get

c:\users\liverpool0912\documents\visual studio 2005\projects\sound\sound\sound.cpp(13) : error C2440: 'initializing' : cannot convert from 'const char [14]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\liverpool0912\documents\visual studio 2005\projects\sound\sound\sound.cpp(16) : error C2664: 'sndPlaySoundW' : cannot convert parameter 1 from 'char' to 'LPCWSTR'

ok im really confused
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

Re: Play sound

Posted 26 August 2008 - 06:52 AM

From here:

Quote

A wide-character string is represented as a wchar_t[] array and is pointed to by a wchar_t* pointer. Any ASCII character can be represented as a wide character by prefixing the letter L to the character. For example, L'\0' is the terminating wide (16-bit) NULL character. Similarly, any ASCII string literal can be represented as a wide-character string literal by prefixing the letter L to the ASCII literal (L"Hello").

Was This Post Helpful? 0
  • +
  • -

#5 liverpool0912  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 04-June 08

Re: Play sound

Posted 26 August 2008 - 06:57 AM

LPTSTR  filename[255]="26 - Halo.wav"; //file must be in same directory as executeable



same error

i even did this

LPTSTR ="26 - Halo.wav"; //file must be in same directory as executeable



same error T.T
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

Re: Play sound

Posted 26 August 2008 - 07:08 AM

LPCWSTR filename = L"26 - Halo.wav";

Was This Post Helpful? 0
  • +
  • -

#7 liverpool0912  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 04-June 08

Re: Play sound

Posted 26 August 2008 - 07:44 AM

#include <iostream>

#include <windows.h>
#include <mmsystem.h> //Windows multimedia stuff
#include <winbase.h> //defines sleep function
void main(void)
{
	  

LPCWSTR filename = L"26 - Halo.wav";  
sndPlaySound(filename,SND_LOOP);
//using SND_ASYNC will cause program execution to continue
//using SND_SYNC will cause the program to halt execution until
//the sound is done playing
//using SND_LOOP will cause the sound to play over and over.
//SND_LOOP must be used with SND_SYNC like so,
//sndPlaySound(filename, SND_SYNC | SND_LOOP);;

}



????????

C:\Users\liverpool0912\Documents\Visual Studio 2005\Projects\wtff\Debug\wtff.exe : fatal error LNK1120: 1 unresolved externals
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

Re: Play sound

Posted 26 August 2008 - 08:02 AM

Perhaps this MSDN thread might help.
Was This Post Helpful? 0
  • +
  • -

#9 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,137
  • Joined: 14-September 07

Re: Play sound

Posted 26 August 2008 - 08:05 AM

one would have to describe the linker error in greater detail for anyone to be of service. Which function/variable, etc... is the unresolved external?
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

Re: Play sound

Posted 26 August 2008 - 08:15 AM

I'm sure it can't find the sndPlaySound function because he needs to link winmm.lib.
Was This Post Helpful? 0
  • +
  • -

#11 liverpool0912  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 04-June 08

Re: Play sound

Posted 26 August 2008 - 09:34 AM

working on it thanks for the link btw
Was This Post Helpful? 0
  • +
  • -

#12 liverpool0912  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 04-June 08

Re: Play sound

Posted 26 August 2008 - 05:40 PM

hehe it works now but i got a problem my sound only runs for a while and it stops suddenly help!!!!!!!!!!!1

#include <iostream>
#pragma comment(lib, "winmm.lib")
#include <windows.h>
#include <mmsystem.h> //Windows multimedia stuff
#include <winbase.h> //defines sleep function
void main(void)
{
	  

LPCWSTR filename = L"26 - Halo.wav";  
sndPlaySound(filename,SND_LOOP);
//using SND_ASYNC will cause program execution to continue
//using SND_SYNC will cause the program to halt execution until
//the sound is done playing
//using SND_LOOP will cause the sound to play over and over.
//SND_LOOP must be used with SND_SYNC like so,
//sndPlaySound(filename, SND_SYNC | SND_LOOP);;

}


Was This Post Helpful? 0
  • +
  • -

#14 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

Re: Play sound

Posted 26 August 2008 - 07:52 PM

http://nibuthomas.wo...ay-a-wave-file/

Note, I found this using Google.
Was This Post Helpful? 1

#15 liverpool0912  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 04-June 08

Re: Play sound

Posted 26 August 2008 - 10:53 PM

zomg i love u thx!!!
Was This Post Helpful? 0
  • +
  • -

#16 didair  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-July 08

Re: Play sound

Posted 29 August 2008 - 01:58 PM

View PostJackOfAllTrades, on 26 Aug, 2008 - 07:52 PM, said:

http://nibuthomas.wo...ay-a-wave-file/

Note, I found this using Google.



THANKS!
:D :D :D
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2