Re: playing wavs under win98

new topic     » goto parent     » topic index » view thread      » older message » newer message

Thanks, Bryan. winsock.e is already include win32lib. boy this is going to
be so cool!

Alan

----- Original Message -----
From: "Brian Broker" <bkb at CNW.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Wednesday, March 22, 2000 11:57 AM
Subject: Re: playing wavs under win98


> On Tue, 21 Mar 2000 19:47:22 -0600, Alan Tu wrote:
>
> >How can I play a WAV file in Windows? Thanks.
>
> You could include David Cuny's Win32Lib and use the 'playSound' function.
> If you don't want the overhead of Win32Lib, then here is the essential
code
> (ripped from Win32Lib):
>
> -- start essential code --
> include msgbox.e
> include dll.e
>
> -- declare integer to hold result of
> --   message_box and playSound functions
> integer ok
>
> --------------------------------------------
> -- wrapper for open_dll with error checking
> global function linkDLL(sequence name)
>
>     -- dynamically link a DLL
>     atom handle
>
>     -- open the dll
>     handle = open_dll( name )
>
>     if handle = NULL then
>
>         -- give error and abort
>         ok = message_box( "Couldn't find DLL " & name,
>                         "Error", MB_ICONHAND+MB_TASKMODAL )
>
>         -- abort
>         abort(1)
>
>     end if
>
>     return handle
>
> end function
>
> ------------------------------------------------
> -- wrapper for define_c_func with error checking
> function linkFunc(atom dll, sequence name, sequence args, atom result)
>
>     -- dynamically link a C routine as a Euphoria function
>     integer handle
>
>     handle = define_c_func(dll, name, args, result)
>     if handle = -1 then
>         -- give error and abort
>         ok = message_box( "Couldn't link to C function " & name,
>                         "Error", MB_ICONHAND+MB_TASKMODAL )
>         -- abort
>         abort(1)
>     end if
>     return handle
> end function
>
> ------------------------------------------------------------
>
> constant
>   -- get handle for winmm.dll
>   winmm = linkDLL("winmm.dll"),
>   -- get handle for PlaySound function in winmm.dll
>   xPlaySound = linkFunc(winmm, "PlaySound", {C_INT, C_INT, C_INT}, C_INT),
>     -- Windows constants for PlaySound function
>     SND_FILENAME = #00020000,
>     SND_ASYNC    = #00000001
>
> -----------------------------------------
> -- wrapper for Windows PlaySound function
> function playSound( sequence fileName )
>
>     atom result, file_string
>
>     -- convert to strings
>     file_string = allocate_string( fileName )
>
>     -- play the sound
>     result = c_func( xPlaySound, {file_string, NULL,
>                          or_bits(SND_FILENAME, SND_ASYNC)})
>
>     -- free the string
>     free( file_string )
>
>     -- return result
>     return result
>
> end function
>
> ---------------------------------------
> -- example usage for playSound function
> ok = playSound( "soundfile.wav" )
> puts( 1, "Playing sound. Press a key to end demo..." )
> while get_key()=-1 do
> -- don't end program before sound is played
> end while
>
> -- Brian
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu