VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Play wav from resource files with API sndPlaySound

by Knoton (15 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

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

Upload

Download this snippet    Add to My Saved Code

Play wav from resource files with API sndPlaySound Comments

No comments have been posted about Play wav from resource files with API sndPlaySound. Why not be the first to post a comment about Play wav from resource files with API sndPlaySound.

Post your comment

Subject:
Message:
0/1000 characters