Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

beep (kernel32)
 
.
Summary
Generates simple tones on the speaker.

C# Signature:

[DllImport("kernel32.dll")]
static extern bool Beep(uint dwFreq, uint dwDuration);

VB Signature:

Declare Function Beep Lib "kernel32.dll" (dwFreq As Integer, _
   dwDuration As Integer) As Boolean

Notes:

Unlike MessageBeep, this function is synchronous. (It doesn't return control to its caller until the sound finishes.)

Tips & Tricks:

Please add some sample code!

Sample Code:

The following sample plays the PC speaker in a series of ascending frequencies:

using System;
using System.Runtime.InteropServices;

class BeepSample
{
    [DllImport("kernel32.dll")]
    static extern bool Beep(uint dwFreq, uint dwDuration);

    static void Main()
    {
        Console.WriteLine("Testing PC speaker...");
        for (uint i = 100; i <= 20000; i++)
        {
            Beep(i, 5);
        }
        Console.WriteLine("Testing complete.");
    }
}

Added by David C. Carachi

Alternative Managed API:

System.Console.Beep, coming in v2.0 (Whidbey) of the .NET Framework

Documentation
Beep on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions