Learning never exhausts the mind

Published on by

This short snippet uses a system call to sound the PC speaker at a given frequency and duration.
[DllImport("Kernel32.dll")]
public static extern bool Beep(UInt32 frequency, UInt32 duration);
public static void BeepMe()
{
  int Frequency = 500;
  int DurationInMS = 100;
  Beep(Frequency, DurationInMS);
}
2 thoughts on “Beeping the PC Speaker in C#
  • 23rd November 2009 at 12:00 am

    Error 1 The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?) C:Documents and Settings[Anonymous]My DocumentsVisual Studio 2008Projects[Private Project][Private Project]Form1.cs 68 10 [Private Project]

    What to do?

    Reply
    • Tim Trott
      10th December 2009 at 12:00 am

      Try adding

      using System.Runtime.InteropServices;

      Reply

Leave a Reply

Fields marked with * are mandatory.

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.