VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Play wav from resource files with API sndPlaySound

Knoton  (15 Submissions)   Windows API Call/Explanation   Visual Basic 3.0   Beginner   Wed 3rd February 2021

This is a very simple API wrapper in a bas module for playing a wav file within a resource file using the API function sndPlaySound.
I tried to figure out how to do this for some time and thought I should share it with you. I belive that for you experienced programmers, out there who are used to work with API, this is simple. But hopefully it will help out someone.
I have included the bas module in case the formatting of the code will be to hard to read.
I got great help from sotirisdj who had a project who thought me this technique.

API Declarations
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Enum SoundTypes
SoundSync = &H0
SoundASync = &H1
SoundMemory = &H4
SoundLoop = &H8
SoundNoStop = &H10
SoundNoDefault = &H2
End Enum
Public Sub PlaySound(ResNameID As Variant, ResType As Variant, SoundFlags As SoundTypes)
sndPlaySound StrConv(LoadResData(ResNameID, ResType), vbUnicode), SoundFlags
End Sub
'Example on how to use it
PlaySound "NameOfSound", "Sound", SoundASync Or SoundMemory

Rate Play wav from resource files with API sndPlaySound (4(4 Vote))
Play wav from resource files with API sndPlaySound.bas

Play wav from resource files with API sndPlaySound Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters