Solved

using PlatSound function

Posted on 1997-10-20
4
207 Views
Last Modified: 2013-11-20
I have a   buzz.wav wave file to play. I use
 PlaySound("buzz.wav",NULL, SND_ASYNC);

to play it. It works no problem (buzz.wav is 10K much less than
recommended 100K, fine). problem is I do want to include buzz.wav
to my project as import resource and use PlaySound to acess
to the resource directly (static binding of wav resource);
How shoul I do it ?  SAY MY RESOURCE id is ID_WAV_BUZZ.

I tried several combinations but it wont take
BOOL PlaySound( LPCSTR pszSound, HMODULE hmod, DWORD fdwSound );

I only know fdwSound  =  SND_RESOURCE|SND_ASYNC

but I need to give my resource id  ID_WAV_BUZZ also how ?
is it to load the resource first and use the handle ?

thanks
0
Comment
Question by:has
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
wpinto earned 50 total points
ID: 1308498
Try the following, it should work

--------------------------------------------------------------------------------------
PlaySound("ID_WAV_BUZZ", AfxGetInstanceHandle(), SND_RESOURCE | SND_ASYNC);

In the .rc file
ID_WAV_BUZZ   WAVE   buzz.wav
--------------------------------------------------------------------------------------

If you want to load the resource, try the following code:

--------------------------------------------------------------------------------------
    BOOL bRtn;
    LPSTR lpRes;
    HANDLE hResInfo, hRes;
 
    /* Find the WAVE resource. */
 
    hResInfo = FindResource(AfxGetInstanceHandle(), lpName, "WAVE");
    if (hResInfo == NULL)
        return FALSE;
 
    /* Load the WAVE resource. */
 
    hRes = LoadResource(AfxGetInstanceHandle(), hResInfo);
    if (hRes == NULL)
        return FALSE;
 
    /* Lock the WAVE resource and play it. */
 
    lpRes = LockResource(hRes);

    if (lpRes != NULL) {
        bRtn = sndPlaySound(lpRes, SND_MEMORY | SND_SYNC |
            SND_NODEFAULT);
        UnlockResource(hRes);
    }
    else
        bRtn = 0;
 
    /* Free the WAVE resource. */
 
    FreeResource(hRes);
--------------------------------------------------------------------------------------
0
 

Author Comment

by:has
ID: 1308499
In the .rc file

IDR_WAV_BUZZ   WAVE DISCARDABLE  "buzz.wav"

in the .cpp file i tried

PlaySound("IDR_WAV_BUZZ",AfxGetInstanceHandle(),SND_RESOURCE|SND_ASYNC);     did not work, i also tried AfxGetResourceHandle()
nothing !

I tried
hRes = LoadResource(AfxGetInstanceHandle(), hResInfo);

but hRes is NULL always. with  AfxGetResourceHandle() also NULL.

any ideas ?

0
 
LVL 2

Expert Comment

by:wpinto
ID: 1308500
Its definitely strange since it worked fine for me
(VC++ 4.2, Windows NT 4.0)

Some troubleshooting tips:
* Make sure you are changing the right file (ie. files from your current project)
* Make sure that you have included the file <mmsystem.h> & linked your project with winmm.lib
* I am assuming here that the .wav file is in the same directory as the project. Please double-click on this .wav file (from Explorer) &  check if you get any sound
* Make sure that the .rc file is getting compiled

If all this fails, try creating a simple project using AppWizard.

In the .rc file add
IDR_WAV_BUZZ WAVE DISCARDABLE "buzz.wav"

in the .cpp file (OnAppAbout() function) add
PlaySound("IDR_WAV_BUZZ",AfxGetInstanceHandle(),SND_RESOURCE|SND_ASYNC);
before creating the About dialog box.
Also add #include <mmsystem.h> to this cpp file

& link this project with winmm.lib

Now whenever you click on Help->About(), you should get some sound. This is how I tested it & it worked fine for me.

Hope this helps

Wilfred
0
 

Author Comment

by:has
ID: 1308501
thank you very much
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Whole sheet autoscrub still needed 19 44
List out all word 7 224
method notes when mouse over in eclipse 5 68
Not needed 13 58
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now