Hi,

I know that the Win32 API call "PlaySound" will play a wav file located externally, but isn't there a way of embedding a sound file into an executable (or DLL)? And if so, what API call would be used to play the file ... would some DirectSound function be needed?

I would think a wav would be a resource, thus could be compiled via rc. (Under the Mac OS, sound files are embedded in resource files).

Thank you.
Posted on 2003-06-09 22:09:12 by Masmer
PlaySound will also play a sound from a resource.

use SND_RESOURCE in the third param.
First param becomes the resource ID.


Here are the third flag options:


Flags for playing the sound. The following values are defined:

SND_APPLICATION

The sound is played using an application-specific association.

SND_ALIAS

The pszSound parameter is a system-event alias in the registry or the WIN.INI file. Do not use with either SND_FILENAME or SND_RESOURCE.

SND_ALIAS_ID

The pszSound parameter is a predefined sound identifier.

SND_ASYNC

The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL.

SND_FILENAME

The pszSound parameter is a filename.

SND_LOOP

The sound plays repeatedly until PlaySound is called again with the pszSound parameter set to NULL. You must also specify the SND_ASYNC flag to indicate an asynchronous sound event.

SND_MEMORY

A sound event's file is loaded in RAM. The parameter specified by pszSound must point to an image of a sound in memory.

SND_NODEFAULT

No default sound event is used. If the sound cannot be found, PlaySound returns silently without playing the default sound.

SND_NOSTOP

The specified sound event will yield to another sound event that is already playing. If a sound cannot be played because the resource needed to generate that sound is busy playing another sound, the function immediately returns FALSE without playing the requested sound.
If this flag is not specified, PlaySound attempts to stop the currently playing sound so that the device can be used to play the new sound.

SND_NOWAIT

If the driver is busy, return immediately without playing the sound.

SND_PURGE

Sounds are to be stopped for the calling task. If pszSound is not NULL, all instances of the specified sound are stopped. If pszSound is NULL, all sounds that are playing on behalf of the calling task are stopped.
You must also specify the instance handle to stop SND_RESOURCE events.

SND_RESOURCE

The pszSound parameter is a resource identifier; hmod must identify the instance that contains the resource.

SND_SYNC

Synchronous playback of a sound event. PlaySound returns after the sound event completes.


RobotBob
Posted on 2003-06-09 23:08:52 by RobotBob
You can include a wav file in your resource section this way:

#define IDC_WAV1 1001
IDC_WAV1 WAVE DISCARDABLE testn.WAV

Use PlaySound to play it :

invoke PlaySound,1001,hInst,SND_RESOURCE
Posted on 2003-06-09 23:35:55 by donkey
You use it this way.



push &SND_RESOURCE
push D$hInstance ;handle of our program
push 1 ;wave ID
call 'WINMM.PlaySoundA' ;API Function

or with a call macro


call 'WINMM.PlaySoundA' 1 D$hInstance &SND_RESOURCE

No library needed.

Just add the wav to the exe directly without a rc.exe
Resources|Wav|Load Wave


RobotBob SpAsm Devotee :)
Posted on 2003-06-10 00:39:46 by RobotBob
I figured with a nick like Masmer he would want it in MASM code.
Posted on 2003-06-10 00:48:29 by donkey
Only trying to plug spasm syntax examples where ever I can.
thats all. lol.

Because I was told that masm32 sucess has ridden on the number of examples.
Through many peoples daily work, that will change.

Now that microsoft seems to be charging for the ddk. (its not a free download anymore, i tried)

RobotBob
Posted on 2003-06-10 00:52:22 by RobotBob
I should start plugging GoAsm :grin:

The worst part is that I thought about ordering it and I can't get past the first page. But then the bottom of the page says it all:

Last Updated: April 01, 2003
Posted on 2003-06-10 00:59:04 by donkey
Thanks guys!

Soon after posting, I searched though some old Windows 95 books and found that PlaySound and sndPlaySound could do it. There was a short example of using sndPlaySound in C which I converted to Masm32. Including the wav file in the res file wasn't difficult ... but using sndPlaySound, FindResource, LoadResource and LockResource calls wasn't working. (FindResource was returning NULL in eax.)

After two hours of hair pulling, I'm glad I checked this forum. :) I'll use PlaySound instead. Also the rc file will need adjustment.

:alright:

Added "OR SND_ASYNC" to the Invoke and it works as hoped.
Posted on 2003-06-10 01:20:51 by Masmer