Generate a beep in the PC speaker using C# and an unmanaged call to the Beep() function that is part of the Windows kernel.
1. using System;
2. using System.Collections.Generic;
3. using System.ComponentModel;
4. using System.Data;
5. using System.Windows.Forms;
6. using System.Runtime.InteropServices;
7.
8. namespace Sample
9. {
10. public partial class Form1 : Form
11. {
12. public Form1()
13. {
14. InitializeComponent();
15. }
16.
17. [DllImport("kernel32.dll")]
18. public static extern bool Beep(int BeepFreq, int BeepDuration);
19.
20. private void button1_Click(object sender, EventArgs e)
21. {
22. Beep(500, 100);
23. }
24. }
25.}