Results 1 to 12 of 12

Thread: [RESOLVED] winmm.dll keeps causing Errors and Crashes?

  1. #1

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Resolved [RESOLVED] winmm.dll keeps causing Errors and Crashes?

    Hello,

    I get vb to play a sound upon Mouse_Over via the sndPlaySound function.

    All fine, it plays sounds BUT, cos there are a couple of command button
    on t he form (3-4) and when you move the mouse over all of them, the sound is played and then the program causes a Crash!! Stating winmm.dll caused the error.

    Is there a better way of handling sounds??
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  2. #2
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: winmm.dll keeps causing Errors and Crashes?

    I have to same error but only running under Windows XP when I play a sound from a resource file.
    VB Code:
    1. Const SND_MEMORY = &H4
    2. Const SND_ASYNC = &H1
    3. Const SND_NODEFAULT = &H2
    4.  
    5. Public Declare Function sndPlaySound Lib "winmm.dll" Alias _
    6. "sndPlaySoundA" (ByVal lpszSoundName As String, _
    7. ByVal uFlags As Long) As Long
    8.  
    9. Public Sub PlaySound(Soundname As String) 'ResData
    10.  
    11. Dim SoundBuffer As String
    12.    
    13. SoundBuffer = StrConv(LoadResData(Soundname, "WAVE"), vbUnicode)
    14. Call sndPlaySound(SoundBuffer, SND_MEMORY Or SND_ASYNC Or SND_NODEFAULT)
    15.  
    16. End Sub
    Last edited by Keithuk; Oct 25th, 2006 at 06:19 AM.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  3. #3
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: winmm.dll keeps causing Errors and Crashes?

    Quote Originally Posted by some1uk03
    Is there a better way of handling sounds?
    Give us a clue and post your code . You could use mciSendString or mciExecute - but if your sounds are stored in a res file, you have to create temporary files from them first.
    Quote Originally Posted by Keithuk
    I have to same error but only running under Windows XP when I play a sound from a resource file.
    Try using PlaySound instead of sndPlaySound.

    You may both find the problem disappears if you purge the sound file from memory before trying to play it again.

    VB Code:
    1. Option Explicit
    2.  
    3. 'Form level code.
    4.  
    5. 'YOU MUST COMPILE TO AN EXECUTABLE TO MAKE IT WORK !!!
    6. '-----------------------------------------------------
    7.  
    8. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
    9.    (ByVal lpszName As Long, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    10.  
    11. 'Required constants.
    12. Const SND_ASYNC = &H1 'Play asynchronously.
    13. Const SND_RESOURCE = &H40004 'Name is a resource name or atom.
    14. Const SND_PURGE = &H40 'Release memory.
    15.  
    16. Private Sub mnuMusic_Click(Index As Integer)
    17.     Dim RetVal As Long
    18.      
    19. 'Reference nothing and purge memory.
    20.    RetVal = PlaySound(0, App.hInstance, SND_PURGE)
    21.  
    22. 'Reference the res file and ... Top Of The Pops ...
    23.    RetVal = PlaySound(101, App.hInstance, SND_RESOURCE Or SND_ASYNC)
    24. End Sub
    Last edited by schoolbusdriver; Oct 26th, 2006 at 05:03 AM. Reason: typo...

  4. #4
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: winmm.dll keeps causing Errors and Crashes?

    Does anyone know the difference between
    VB Code:
    1. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
    2. (ByVal lpszName As String, ByVal hModule As Long, _
    3. ByVal dwFlags As Long) As Long
    4.  
    5. Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
    6. (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    sndPlaySound is the API call thats been used for many years. When did PlaySound come about? It has the extra call App.hInstance for ByVal hModule As Long.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  5. #5
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: winmm.dll keeps causing Errors and Crashes?

    Quote Originally Posted by schoolbusdriver
    but if your sounds are stored in a res file, you have to create temporary files from them first.
    I don't think you don't have to extract the wave file before you play them. I've never seen any in Windows\Temp or App.Path. Its the same as putting bmp's, cur's and ico's in a resource file. You just extract them directly to your app. You have to extract jpg's and gif's to a temp file and any other Custom addin.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  6. #6

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: winmm.dll keeps causing Errors and Crashes?

    SCHOOLBUSDRIVER, sorry but ur code doesnt work for me.

    I get no sound back, even when i compile my app.

    VB Code:
    1. mSound = StrConv(LoadResData(102, "SOUND"), vbUnicode)
    2.        PlaySound mSound, App.hInstance, flags&

    and also whats the difference between,

    sndPlaySound & PlaySound ?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  7. #7
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: winmm.dll keeps causing Errors and Crashes?

    Quote Originally Posted by Keithuk
    When did PlaySound come about? It has the extra call App.hInstance for ByVal hModule As Long.
    Not sure, but it's been around for a while. MS says sndPlaySound is a cut down version of PlaySound, so which came first . It may have been an *undocumented* API initially. MS are good at that.
    Quote Originally Posted by Keithuk
    ...don't have to extract the wave...
    My fuzzy - I was referring to mciSendString and mciExecute.
    Quote Originally Posted by some1uk03
    I get no sound back, even when i compile my app.
    VB Code:
    1. mSound = StrConv(LoadResData(102, "SOUND"), vbUnicode)
    2.        PlaySound mSound, App.hInstance, flags&

    and also whats the difference between,

    sndPlaySound & PlaySound ?
    1) Did you try my code, and not your own ?? You don't need "mSound = StrConv(LoadResData(102, "SOUND"), vbUnicode)"

    2) See above.
    Last edited by schoolbusdriver; Oct 25th, 2006 at 05:03 PM. Reason: Another damn typo...

  8. #8
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: winmm.dll keeps causing Errors and Crashes?

    Quote Originally Posted by schoolbusdriver
    You don't need "mSound = StrConv(LoadResData(102, "SOUND"), vbUnicode)"
    Thats alright providing he is using a resource file as well as me. He hasn't said how he is playing a wave file.

    @schoolbusdriver - your code doesn't work for me either, type mismatch.
    VB Code:
    1. Call PlaySound(App.Path & "\Chimes.wav", _
    2. App.hInstance, SND_RESOURCE Or SND_ASYNC)
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  9. #9
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: winmm.dll keeps causing Errors and Crashes?

    Quote Originally Posted by Keithuk
    Thats alright providing he is using a resource file as well as me. He hasn't said how he is playing a wave file.

    @schoolbusdriver - your code doesn't work for me either, type mismatch.
    VB Code:
    1. Call PlaySound(App.Path & "\Chimes.wav", _
    2. App.hInstance, SND_RESOURCE Or SND_ASYNC)
    As some1uk03's using "LoadResData" (post 6), one can only assume...

    The code I posted is specifically for playing wav files from a res file - specified by SND_RESOURCE - not from HDD... (post 2)

    Actually, I've gone through this before. If you look at Re: VB6 Embed audio - posts 14 - 20 inclusive, it shows the pitfalls...

  10. #10
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: winmm.dll keeps causing Errors and Crashes?

    This is somewhat strange. I've just tried rapid repeated playback (with several PlaySound code combinations) using a variety of wav files. Some will play back repeatedly without problems, and some won't.

    E.g, - "wmpaud1.wav", (which comes with media player) at 347KB repeats OK, as do all files lager than this. "nudge.wav", at 169KB doesn't.

    Even using a wav file editor to increase "nudge.wav"'s file size to 502KB didn't work, so the playback and repeated playback failures appears to be related to the file's format .

    Not a solution, but at least a partial reason...

  11. #11

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: winmm.dll keeps causing Errors and Crashes?

    Does anyone know the difference between

    visual basic code:
    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
    (ByVal lpszName As Long, ByVal hModule As Long, ByVal dwFlags As Long) As Long

    Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Ok i figured it out.

    the PlaySound Function requires a LONG as you can see (ByVal lpszName As Long)
    Which is what Schoolbusdriver was saying and from hes point of view is correct. I got it working.

    Where As:

    sndPlaySound Function requires a STRING as you can see (ByVal lpszSoundName As String)
    Which means you could use the StrConv(LoadResData(101, "SOUND"), vbUnicode) function to convert the .RES data to a string and play it back.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  12. #12
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: [RESOLVED] winmm.dll keeps causing Errors and Crashes?

    I know it's marked as resolved, but as a final bit of info:

    VB Code:
    1. 'Note the different ways you can call PlaySound & sndPlaySound, depending
    2. 'on whether you want to pass a number or string.
    3.  
    4. 'PlaySound.
    5. 'Pass a String reference to lpszName.
    6. Private Declare Function PlaySoundString Lib "winmm.dll" Alias "PlaySoundA" _
    7.    (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    8.  
    9. 'Pass a Long Resource reference to lpszName.
    10. Private Declare Function PlaySoundResource Lib "winmm.dll" Alias "PlaySoundA" _
    11.    (ByVal lpszName As Long, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    12.  
    13.  
    14. 'sndPlaySound.
    15. 'Pass a String reference to lpszSoundName.
    16. Private Declare Function sndPlaySoundString Lib "winmm.dll" Alias "sndPlaySoundA" _
    17.    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    18.  
    19. 'Pass a Long Resource reference to lpszSoundName.
    20. Private Declare Function sndPlaySoundLong Lib "winmm.dll" Alias "sndPlaySoundA" _
    21.    (ByVal lpszSoundName As Long, ByVal uFlags As Long) As Long

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