Re: playing wavs under win98
- Posted by Brian Broker <bkb at CNW.COM> Mar 22, 2000
- 416 views
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