Solved

using PlatSound function

Posted on 1997-10-20
4
231 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

717 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