Using LoadResData with Binary DataLast reviewed: May 16, 1996Article ID: Q141505 |
The information in this article applies to:
SUMMARYVisual Basic 4.0 introduces a new function called LoadResData, which can be used to retrieve binary data from a resource (.res) file. The sample in this document demonstrates how to create a resource file and use binary data from it in all versions of Visual Basic 4.0.
MORE INFORMATIONThe following code is a resource script that can be compile by using the 16 and 32-bit versions of Rc.exe.
/////////////////////////////////////////////////////////////////////// ////// // Myres.rc - 16 & 32 bit script. This must be compiled into two .res // files using the 16 & 32 bit versions of RC. /////////////////////////////////////////////////////////////////////// ////// // Wave Resources - You must copy these files from your \Windows // directory to the directory where your .rc script resides. CHIMES WAVE DISCARDABLE "Chimes.wav" DING WAVE DISCARDABLE "Ding.wav" Steps to Create a Resource File
Steps to Run the Sample Application
(lpszSoundName As Any, ByVal uFlags AsLong) As Long #Else
Private Declare Function sndPlaySound Lib "MMSYSTEM" ( _
lpszSoundName As Any, ByVal uFlags%) As Integer
#End If
'*********************************************************************
' Flag values for wFlags parameter.
'*********************************************************************
Public Const SND_SYNC = &H0 ' Play synchronously (default)
'Public Const SND_ASYNC = &H1 ' Play asynchronously (see
' note below!)
Public Const SND_NODEFAULT = &H2 ' Don't use default sound
Public Const SND_MEMORY = &H4 ' lpszSoundName points to a
' memory file.
Public Const SND_LOOP = &H8 ' Loop the sound until next
' sndPlaySound.
Public Const SND_NOSTOP = &H10 ' Don't stop any currently
' playing sound.
'*********************************************************************
' Plays a wave file from a resource.
'*********************************************************************
Public Sub PlayWaveRes(vntResourceID As Variant, Optional vntFlags)
'-----------------------------------------------------------------
' WARNING: If you want to play sound files asynchronously in
' Win32, then you MUST change bytSound() from a local
' variable to a module-level or static variable. Doing
' this prevents your array from being destroyed before
' sndPlaySound is complete. If you fail to do this, you
' will pass an invalid memory pointer, which will cause
' a GPF in the Multimedia Control Interface (MCI).
'-----------------------------------------------------------------
Dim bytSound() As Byte ' Always store binary data in byte arrays!
bytSound = LoadResData(vntResourceID, "WAVE")
If IsMissing(vntFlags) Then
vntFlags = SND_NODEFAULT Or SND_SYNC Or SND_MEMORY
End If
If (vntFlags And SND_MEMORY) = 0 Then
vntFlags = vntFlags Or SND_MEMORY
End If
sndPlaySound bytSound(0), vntFlags
End Sub
|
Additional reference words: vb4win vb4all 4.00 WAVE LOADRESDATA RESOURCES
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |