0

It's spring break, so let's beep in C# code, actually a 440 Hz A. We are just borrowing the Beep() function from the Windows kernel.

// using InteropServices
// the necessary WinApi functions are in kernel32.dll
// in C# Handle = IntPtr  DWORD = uint   WORD = int
// just a console program compiled with:
// C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe

using System;
using System.Runtime.InteropServices;  // DllImport()

class Class1
{
  // WinApi Beep() is in kernel32.dll  
  [DllImport("kernel32")]
  private static extern int Beep(int dwFreq, int dwDuration);

  static void Main(string[] args)
  {
    Console.WriteLine("It's spring time so let's beep!!!!\n\n");
        
    int freq = 440;      // hertz
    int duration = 2000;  // milliseconds
    Console.WriteLine("Beeping at " + freq + " Hz for " + duration + " milliseconds");
    Beep(freq, duration);
  }
}
2
Contributors
1
Reply
5
Views
9 Years
Discussion Span
Last Post by HLA91
0

Awesome I modified it sent it to my friend and it said
"If your computer beeps it has a virus" and he went nuts I did tell him the truth (after half hour)

Cheers

HLA91

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.