PlayAudioRes




#If Win32 Then
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
#Else
Public Declare Function sndPlaySound Lib "MMSYSTEM.DLL" _
(ByVal lpszSoundName As Any, ByVal wFlags As Integer) As Integer
#End If
Sub PlaySound(ByVal ResourceId)
Dim SoundBuffer As Variant
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Const SND_MEMORY = &H4
Const RESType = "WAVE"

If Not IsNumeric(ResourceID) Then
Call sndPlaySound(CStr(ResourceId), SND_ASYNC Or SND_NODEFAULT)
Else
#If Win32 Then
SoundBuffer = StrConv(LoadResData(CInt(ResourceId), RESType), vbUnicode)
#Else
SoundBuffer = LoadResData(CInt(ResourceId), RESType)
#End If
Call sndPlaySound(CStr(SoundBuffer), _
SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)
End If
' DoEvents is Important!

DoEvents
End Sub

To play a wavefile ResourceID must be the wave's filename.
To play a wave resource add it to your resource file and
use the type WAVE, ResourceID must be the integer resource
identifier.










( playaudiores.html )- by Paolo Puglisi - Modifica del 17/12/2023