19 out of 30 rated this helpful - Rate this topic

Beep function

Applies to: desktop apps only

Generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its caller until the sound finishes.

Syntax

BOOL WINAPI Beep(
  __in  DWORD dwFreq,
  __in  DWORD dwDuration
);

Parameters

dwFreq [in]

The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).

dwDuration [in]

The duration of the sound, in milliseconds.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

A long time ago, all PC computers shared a common 8254 programable interval timer chip for the generation of primitive sounds. The Beep function was written specifically to emit a beep on that piece of hardware.

On these older systems, muting and volume controls have no effect on Beep; you would still hear the tone. To silence the tone, you used the following commands:

net stop beep

sc config beep start= disabled

Since then, sound cards have become standard equipment on almost all PC computers. As sound cards became more common, manufacturers began to remove the old timer chip from computers. The chips were also excluded from the design of server computers. The result is that Beep did not work on all computers without the chip. This was okay because most developers had moved on to calling the MessageBeep function that uses whatever is the default sound device instead of the 8254 chip.

Eventually because of the lack of hardware to communicate with, support for Beep was dropped in Windows Vista and Windows XP 64-Bit Edition.

In Windows 7, Beep was rewritten to pass the beep to the default sound device for the session. This is normally the sound card, except when run under Terminal Services, in which case the beep is rendered on the client.

Examples

The following example demonstrates the use of this function.


Beep( 750, 300 );


Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Error Handling Functions
MessageBeep
Notifying the User

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
beep
BOOL WINAPI Beep(
  __in  DWORD dwFreq,
  __in  DWORD dwDuration
);
C# & VB.NET
[DllImport("Kernel32.dll")]
public static extern bool Beep(Int32 dwFreq, Int32 dwDuration);

<DllImport("Kernel32.dll")> _
Public Shared Function Beep(dwFreq As Int32, dwDuration As Int32) As Boolean
End Function
Cool function!
Beep(8000, 60000);
my ears...
works well on Win7
usefull than MessageBeep.
Also works on Vista?
Seems to work fine on Vista (32-bit HP machine), so has there been any update in the mean time?
Works fine
As previously mentioned, it works fine on Windows 7 x64, although you may experience a slight click at the end of the sound.
Works on Windows 7 x64
Works fine on Windows 7 x64. Shame about Vista.
Beep functions still invalidated?
Hello !

There is in no way any annotation, that, on x64 OS, these API will no longer work! One may call this APIs without error, but you'll never get any tone/sound. Micrsosft should ether officielly remove the APIs [what I do NOT wish, they do] or they should give back a driver neccessary for use with this API. It is very useful in server work context, where one needs a minimal feeback - for example, for longer running scripts - because there is usually no sound hardware present. See my connect entry: https://connect.microsoft.com/WindowsServerFeedback/feedback/ViewFeedback.aspx?FeedbackID=410551&wa=wsignin1.0.

Best regards!
scamb

Beep
Removing access to the internal speaker was yet another awful move by Microsoft. At least provide an alternative before you invalidate dozens of pieces of software we hoped to run on 7.
Beep
On Windows 7 Beep does not make sound on a motherboard speaker, but on a sound card. I am using Beep as a warning indicator on a machines with no speakers. I really miss this feature. Please consider making it work on a motherboard speaker.
Beep
As a c++ developer I really do miss the Beep(dwFrequency, dwDuration) function. It was so handy,
not least as a primary debug tool. I do hope that ms has considered putting it back into 7!


---
This is also broken in Windows 7 and also Server 2008(R2). We use this feature to find machines in the server farm.