Advertisement
6_2008-2009 Sound/MP3 #210033

Play sound from resource

If you want to play sounds in your program, but don't want to ship extra .wav files and make sure there in the right path, or you don't want people ripping off your stored .wav files, you can play sounds from a resource file built in to your .exe file. Although Windows resources have a "WAVE" type, Visual Basic doesn't support it. The answer: use a binary resource and play the sound from memory!

AI

AIサマリー: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

ソースコード
original-source
'Declare a byte array to put the sound in
Dim Sound() as Byte
'Load the binary resource into the byte array
'101 is the resource identifier of your sound
'"CUSTOM" is the resource type to use (CUSTOM is
'the default for binary)
'
'LoadResData automatically redims the variable
'so it's the right size
Sound = LoadResData(101, "CUSTOM")
'Play the sound
Call PlaySoundMem(VarPtr(Sound(0)), 0, SND_NOWAIT Or SND_NODEFAULT Or SND_MEMORY Or SND_ASYNC Or SND_NOSTOP)
'Clean up memory
'You wouldn't do this right away if you want to
'play the sound over and over
Redim Sound(0)
オリジナルのコメント (3)
Wayback Machineから復元