Monday, July 27, 2009

How can I play a Beep sound in C#.2005 similar to Vb6?

Hello All great,


I need help of you all. I was playing a beep sound during invalid entry in Visual Basic 6. The function was Beep() in VB6.





Now I want to play similar sound in C#.Net 2005 but not getting any function to play a sound similar to VB6 Beep sound.





thanking you

How can I play a Beep sound in C#.2005 similar to Vb6?
You may be able to do it using the Windows API (a system function call)





Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long





Explanations:





· dwFreq


Windows NT:


Specifies the frequency, in hertz, of the sound. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).


Windows 95:


The parameter is ignored.





· dwDuration


Windows NT:


Specifies the duration, in milliseconds, of the sound.


Windows 95:


The parameter is ignored.





Return Values:


If the function succeeds, the return value is nonzero.





If the function fails, the return value is zero. To get extended error information, call GetLastError.
Reply:As the above poster said, new stuff in the .NET 2.0 framework.





You can also do something like this:


My.Computer.Audio.PlaySystemSound


then choose what sound you want:


(Media.SystemSounds.Beep) For example





EDIT: Opps sorry, you were looking for a C# example.


I showed you a VB example.
Reply:In .NET Framework 2.0, we have a brand new method:





Console.Beep() (2 overloads)


http://msdn2.microsoft.com/en-us/library...








Try that! As you said C#.NET 2005, you must be on 2.0 or higher.





The other solution (of using pinvoke and win32 dll) was the only way out up until .Net 1.1.


No comments:

Post a Comment