Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Wav - Res File - How to play.

Posted on 1998-10-25
1
Medium Priority
?
614 Views
Last Modified: 2012-05-04
Hi,

I placed a wav file into a res file using Visual C++ v5.
I gave it the ID 101
I also also placed 2 bitmap. ID 102 and 103 respectably.
I got the bitmaps out using this statement.
Set Picture1 = LoadResPicture(102, 0)
Set Picture2 = LoadResPicture(103, 0)

But when I tried to get the wav out:
Dim b() As Byte
b = LoadResData(101, 10)
It said that there was no 101 res.
But I know it's in there.

So can somebody show me, how to extract a wav from a res, and
then play it?

Thanks
0
Comment
Question by:BabyFace
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
kacklehorn earned 200 total points
ID: 1441466
This is taken directly from Q141505 on Microsofts Knowledge Base.

SUMMARY
=======

Visual 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 INFORMATION
================

The 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
-------------------------------

1. Save the above code in Notepad as Myres.rc in the directory where Rc.exe
   exists on your hard disk.

2. Copy Chimes.wav and Ding.wav from your Windows directory (or your
   \Windows\Media directory on Windows 95 or Windows 98) to the same
   directory where you saved Myres.rc.

3. At the command line, type "RC -r Myres.rc." If you want a 16-bit and 32-
   bit version of your resource file, then you will have to save two copies
   of your resource file as Myres32.rc and Myres16.rc, and compile each
   separately with the appropriate resource compiler.

Steps to Run the Sample Application
-----------------------------------

1. Create a new project and add a command button to Form1.

2. Add the following code to Form1:

'*********************************************************************

      ' Form1.frm - Calls PlayWaveRes to play a wave resource file.

'*********************************************************************

      Sub Command1_Click()
         PlayWaveRes "Chimes"
         PlayWaveRes "Ding"
      End Sub

3. Add your resource file to the project.

4. Type the following code in a new code module:

'*********************************************************************

      ' Baswave.bas - Plays a wave file from a resource using LoadResData.

'*********************************************************************

      Option Explicit
      #If Win32 Then
        Private Declare Function sndPlaySound Lib "winmm" Alias
"sndPlaySoundA" _
                            (lpszSoundName As Any, ByVal uFlags As
Long) 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

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question