PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Strange compile errors

If im putting something like this in my sourcecode (using eMB 3.0):


sndPlaySound("sound.wav", SND_LOOP | SND_FILENAME);



I get this error:


error C2664: 'sndPlaySoundW' : cannot convert parameter 1 from 'char [10]' to 'const unsigned short *'


If im programming with VC++ 6.0 for Windows 95... (using PlaySound), everything works fine.
The problem also appears with MessageBoxes.
What's the problem?
Moose or Chuck · 27 Jun 2001, 11:45 UTC
You can't name a wav file like that. You have to use something like: MAKEINTRESOURCE(IDR_WAVE1).
(in which case you imported the wave into your resource file and gave it that ID in the resource's header file)
Last modification: Moose Master - 06/27/01 at 09:45:45
Moose or Chuck · 27 Jun 2001, 11:46 UTC
But I can't get playsound to work at all. It gives me some linking error whenever I try. (also getting rid of new bug). See my other thread (Linking Error), I need some help on that.
Put an L before the string:

sndPlaySound(L"sound.wav", SND_LOOP | SND_FILENAME);
Moose or Chuck · 27 Jun 2001, 12:24 UTC
So I guessed. sorry......
No, Moose. sndPlaySound() cannot play sounds from a resource identifier in a module. It searches for the sound to play as an entry in the registry or in WIN.INI as a system sound, or it can be the name of a waveform-audio file.  To play from a wave resource identifier, you would use PlaySound().

In this case, sndPlaySound(), SND_FILENAME is not an available flag for the 2nd argument.
Instead, type
Code:
sndPlaySound(_T( "sound.wav" ), SND_LOOP | SND_ASYNC);


I put the SND_ASYNC flag because the function will not return until the sound ends unless it is played asynchronously. But you can leave that out.

Edit: Darn Smileys.
Last modification: JongJungBu - 06/27/01 at 10:28:59

Put an L before the string:

sndPlaySound(L"sound.wav", SND_LOOP | SND_FILENAME);


There is no SND_FILENAME flag for sndPlaySound.
As Fredrick basically said, you need to pass a UNICODE string instead of ASCII. You can place an L in front of the string, but I greatly prefer using the _T( "" ) macro instead because it follows standard C syntax which looks and makes more sense than using the L macro. The following are are methods of forcing the compiler to convert a string to unicode:
_T( "my string" ), L"my string", _TEXT( "my string" )
Using the L macro is also more "dangerous" in that it always converts to a Unicode string. _T and _TEXT will only convert the string if you are building a Unicode app, which makes your code more portable. If you use the L macro then you should not use _t functions. You should use the _w family instead since you are specifically using only wide-character strings.

You do not use the SND_FILENAME flag. sndPlaySound will load the file if that is what your string refers to.

Dan East

Friggen smileys: Last modification: Dan East - 06/27/01 at 15:27:48
So yer pretty much saying my sample code was right!!! :D
Yep, sorry JJB, I basically said exactly what you did. As Moose will tell you, I'm good at that. ;)

Dan East
Moose or Chuck · 27 Jun 2001, 18:01 UTC
And now that the question is answered by Dan there will be no more replies to this thread.
Either Dan is really good at answering questions, or he has a disease we don't know about.
I will reply anyway.
Heh. That is okay by me Dan. I'm just enjoying that you have confirmed what I posted. Then I can say..."In your Face!"

umm, i just dont know who i can say that to though.