User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 402,636 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,313 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Apr 1st, 2007
Views: 2,838
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.
Last edited : Apr 1st, 2007.
csharp Syntax | 5 stars
  1. // using InteropServices
  2. // the necessary WinApi functions are in kernel32.dll
  3. // in C# Handle = IntPtr DWORD = uint WORD = int
  4. // just a console program compiled with:
  5. // C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe
  6.  
  7. using System;
  8. using System.Runtime.InteropServices; // DllImport()
  9.  
  10. class Class1
  11. {
  12. // WinApi Beep() is in kernel32.dll
  13. [DllImport("kernel32")]
  14. private static extern int Beep(int dwFreq, int dwDuration);
  15.  
  16. static void Main(string[] args)
  17. {
  18. Console.WriteLine("It's spring time so let's beep!!!!\n\n");
  19.  
  20. int freq = 440; // hertz
  21. int duration = 2000; // milliseconds
  22. Console.WriteLine("Beeping at " + freq + " Hz for " + duration + " milliseconds");
  23. Beep(freq, duration);
  24. }
  25. }
Comments (Newest First)
HLA91 | Junior Poster | Oct 13th, 2007
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
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 2:11 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC