Solved

Res File

Posted on 2000-03-07
2
170 Views
Last Modified: 2010-05-02
How to play a wav from res file?
0
Comment
Question by:EasyCoder
2 Comments
 
LVL 13

Accepted Solution

by:
crazyman earned 150 total points
ID: 2592015
#If Win32 Then
Private Declare Function sndPlaySound Lib "winmm" Alias _
   "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) _
   As Long
#Else
Private Declare Function sndPlaySound Lib "MMSYSTEM" ( _
                   lpszSoundName As Any, ByVal uFlags%) As Integer
#End If

' Flag values for wFlags parameter.

'*********************************************************************

Public Const SND_SYNC = &H0        ' Play synchronously (default).
'Public Const SND_ASYNC = &H1      ' Play asynchronously (see
                            ' note below).
Public Const SND_NODEFAULT = &H2   ' Do not use default sound.
Public Const SND_MEMORY = &H4      ' lpszSoundName points to a
                            ' memory file.
Public Const SND_LOOP = &H8        ' Loop the sound until next
                            ' sndPlaySound.
Public Const SND_NOSTOP = &H10     ' Do not stop any currently
                                                  ' playing sound.
Public Sub PlayWaveRes(vntResourceID As Variant, Optional vntFlags)
'-----------------------------------------------------------------
' WARNING:  If you want to play sound files asynchronously in
'           Win32, then you MUST change bytSound() from a local
'           variable to a module-level or static variable. Doing
'           this prevents your array from being destroyed before
'           sndPlaySound is complete. If you fail to do this, you
'           will pass an invalid memory pointer, which will cause
'           a GPF in the Multimedia Control Interface (MCI).
'-----------------------------------------------------------------
Dim bytSound() As Byte ' Always store binary data in byte arrays!

bytSound = LoadResData(vntResourceID, "WAVE")

If IsMissing(vntFlags) Then
   vntFlags = SND_NODEFAULT Or SND_SYNC Or SND_MEMORY
End If

If (vntFlags And SND_MEMORY) = 0 Then
   vntFlags = vntFlags Or SND_MEMORY
End If

sndPlaySound bytSound(0), vntFlags
               End Sub
0
 

Author Comment

by:EasyCoder
ID: 2592025
Wow Fast ..thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question