Play Wav resource

Well, this doesn't really deal with MFC, but its useful knowledge if you don't know how..

Parts of this code I ripped from VC++ 4.1 help, but it was outdated and didn't come close to working.

First of all you need to add the wave files to the .rc file manually like so:

<NameOfSound> WAVE <Location of WAVE.>
Example being
Cool WAVE C:\projects\sounds\cool.wav

Then you need to add this function declarion to the class you plan on using..
BOOL PlayResource(LPSTR lpName)
    BOOL bRtn;
    LPSTR lpRes;
    HANDLE hRes;
    HRSRC hResInfo;
    HINSTANCE Nl=AfxGetInstanceHandle();

    /* Find the WAVE resource. */
    hResInfo= FindResource(Nl,lpName,"WAVE");
    if(hResInfo == NULL)
       return FALSE;
    /* Load the WAVE resource. */

    hRes = LoadResource(Nl,hResInfo);
    if (hRes == NULL)
      return FALSE;

    /* Lock the WAVE resource and play it. */
      return FALSE;

    bRtn = sndPlaySound(lpRes, SND_MEMORY | SND_SYNC);
    if(bRtn == NULL)
      return FALSE;

    /* Free the WAVE resource and return success or failure. */
    return TRUE;

Then to play the sound you simply use:

Example being


  • How to play *.wav when we store it on database

    Posted by Legacy on 01/20/2004 12:00am

    Originally posted by: romi nur ismanto

    How to play *.wav when we store it on database
    Please give me code to play *.wav when thats file is in the database (acces)

  • How can I pause a long wav file and then resume it?

    Posted by Legacy on 10/22/2003 12:00am

    Originally posted by: Wenjun

    I am using PlaySound() to play wav files. However, I did not find the command to pause and resume the playing. Your kind help is highly appreciated.

  • Audio Player Drag and Drop

    Posted by Legacy on 05/13/2003 12:00am

    Originally posted by: Tapas

    Hi i am making a audio player. i have problem abt this.

    1. If i click on wav file it opens the apllication but can't play it.
    2. if i open a file from file open menu it comes to play list but can't play.

    pls give any suggestion.


  • Resource putting automation

    Posted by Legacy on 05/07/2003 12:00am

    Originally posted by: CallMan

    Tell me please - how can i write into the resource file a prety big
    amount of WAV's ? I do not want to make it manually (Menu -> Insert
    ->Resource, etc. )

    Can i in some way automatise this job ?

  • How to play wav on internet ..... Data Streaming

    Posted by Legacy on 12/02/2002 12:00am

    Originally posted by: Maggie

    How to perform Data Streaming on the web page????

    • try this to play a wav file

      Posted by ellav on 03/31/2006 09:17am

      Personally liked the way of Waveform Audio Interface: in just 2 lines you can play a file in PCM as wav file in c# for compact framework 1.0 VS .NET 2003: //Play a filname.wav WaveOut wo = new WaveOut(); wo.Play(filename, 512*1024, 0xffff, 0xffff); //Thats all thanks o the P/Invoke Library Sample available a MSDN help

  • How do you put a background sound in a form in Visual Basic 6

    Posted by Legacy on 11/25/2002 12:00am

    Originally posted by: Thomas Hair

    How do you put a background sound in a form in Visual Basic 6. I really need to know this for a project that I am making. The audio file is a MP3 file 9is this possible to use as a background sound or does it have to be a WAVE file?)

  • How tp play from buffer?

    Posted by Legacy on 08/06/2002 12:00am

    Originally posted by: Anurag

    How would you play the sound streaming in to a buffer? (not a file.. just a buffer..)

  • Wave Streams

    Posted by Legacy on 07/28/2002 12:00am

    Originally posted by: gsc

    Are wave streams for playing multiple wave files simultaneosly? If not, how is this done. I believe it is possible to do this using wave channels, or something, but I am have no idea how. If anyone knows, please help me out by explaining this in your reply. Thanks.

  • Do it the easy way

    Posted by Legacy on 07/16/2002 12:00am

    Originally posted by: sanpee

    Would it be easier if you just say

  • How to get the total time of a wav file?

    Posted by Legacy on 06/24/2002 12:00am

    Originally posted by: jokerhe


  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date