Solved

using PlatSound function

Posted on 1997-10-20
4
209 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 53
move a line in eclipse 3 81
Change to event 1 101
Updating statistics with error notification email in SQL server 4 73
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

13 Experts available now in Live!

Get 1:1 Help Now