Results 1 to 5 of 5

Thread: Playing Wav files from resource file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Talking

    I've loaded a wav file into a res file and I want to play it from my code.
    It's loaded into a res file as "WAV" type, and read from a a .wav file.

    This is what I've done:

    eepSound = LoadResData(101, "WAV")
    sndPlaySound eepSound, SND_NODEFAULT Or SND_ASYNC

    However, I don't get any sound played.

    Anybody want to clue me in as to how to load a wav file into a res file and then play it?

    Thanks!

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    This is what I use:

    ' the declares

    Public Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

    Public Const SND_ASYNC = &H1 ' Play asynchronously
    Public Const SND_NODEFAULT = &H2 ' Don't use default sound
    Public Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file



    ' play the sound
    Dim retVal As Long
    Dim SoundBuffer As String

    SoundBuffer = StrConv(LoadResData(101, "ATM_SOUND"), vbUnicode)
    retVal = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Cool Works Great!

    Frans C -

    Your solution works well!
    Thanks a bunch!

  4. #4
    Junior Member
    Join Date
    Nov 1999
    Posts
    23
    I used the compiler on the vb5 cd and compiled a wav into a resource file, but vb5 tells me that no resource by the identifier i gave it exists!

    Also, here's a little info from http://www.vbapi.com regarding the newer Playsound api call:

    PlaySound
    Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

    Alternate Declare for when using a resource or memory location:
    Declare Function PlaySound_Res Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As Long, ByVal hModule As Long, ByVal dwFlags As Long) As Long

    lpszName
    The name or some other identifier of the sound. Its exact format depends on the flags passed as dwFlags.
    hModule
    A handle to the application module containing the sound resource the play, if needed. If the function does not need this information, pass 0 for this parameter.

    What exactly is a module handle? I know about window handles, but have never heard of module handles! (this api call would be a simpler way of doing the sound playing work...)

  5. #5
    Junior Member
    Join Date
    Nov 1999
    Posts
    23
    I just looked at vb help, it says that the max that LoadResData will load is 64k, however the sound I have in my .res file is 1.2mb! (very long sound file) could this be why loadresdata isn't seeing the resource??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width