Solved

using PlatSound function

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 92
Define unique primary key 9 95
Making an alias 7 115
Is there a simple front-end menu system. 9 124
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

696 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