Search code examples
wpfwindowsaudioc++-clibeep

What should I use to replace the WinAPI Beep() function?


I've got a Visual C++/CLI app which uses beeps to signify good and bad results (used when the user can't see the screen).

Currently I use low pitched beeps for bad results and high pitched beeps for good results:

if( goodResult == true )
{
    Beep(1000, 40);
}
else
{
    Beep(2000, 20);
}

This works okay on my Vista laptop, but I've tried it on other laptops and some seem to play the sounds for less time (they sound more like clicks than beeps) or the sound doesn't play at all.

So I have two questions here:

  1. Is there a more reliable beep function?
  2. Is there a (simple) way I can play a short .wav file or something similar instead (preferred solution).

Solution

  • The Beep function traditionally used the PC speaker, and I guess it is more or less obsolete nowadays. I guess the functionality is handled by the Laptop's BIOS, and thus is hardware dependant. I suggest that you use the PC:s soundcard to play the sound instead.

    Create two tones as WAV files in e.g. Audacity, then play them using e.g. PlaySound.