How can I embed a wav file into a program? How could I have the sound play when the program loads? I don't want to include the wav file as an extra file, I would rather have it in the executable.
Thanks
Printable View
How can I embed a wav file into a program? How could I have the sound play when the program loads? I don't want to include the wav file as an extra file, I would rather have it in the executable.
Thanks
You can have a resource file with your WAV in it. Then on a form load you can load the sound from there:
Code:Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1
Private Const SND_NODEFAULT = &H2
Private Const FLAGS = SND_ASYNC And SND_NODEFAULT
Public Sub PlayWavResource(pintResourceID As Integer)
Dim strSoundBuffer As String
strSoundBuffer = StrConv(LoadResData(pintResourceID, "CUSTOM"), vbUnicode)
Call sndPlaySound(strSoundBuffer, FLAGS)
End Sub
Private Sub Form_Load()
'Assuming that 101 is an ID for the resource
PlayWavResource 101
End Sub