.NET Framework - Why Console.Beep() doen't beep?

Asked By Rafae
09-Feb-08 11:07 PM
I'm studying C# (I've been a VB developer).

I'm making some tests and I need to use Console.Beep(), but it doesn't make
any sound, no matter if I try it in VS2008 beta or VS2005.

Could anybody tell my some hint abouit it?

--
Rafael
SystemSounds
(1)
DllImport
(1)
CharSet
(1)
VB
(1)
Console
(1)
Visual
(1)
Beep
(1)
MessageBeep
(1)
  Cor Ligthert[MVP] replied...
10-Feb-08 01:27 AM
Rafael,

There is not any difference in using classes from Net between Visual Basic
and C#.

The only difference is the program language around that.

So probably there is something else.

Cor
  Sergey Zyuzin replied...
10-Feb-08 10:43 AM
I don't know why it doesn't beep,
you might try this function instead:

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool MessageBeep(int type);


HTH,
Sergey Zyuzin
  Mick Doherty replied...
10-Feb-08 06:21 AM
Console.Beep uses the PC Speaker rather than the soundcard (the same speaker
that the BIOS uses).
Do you have a PC Speaker?

Console.Beep(); is the equivelant of calling the Interop Beep method:
\\\
Beep(800, 200);
///
...where the method is defined as:
\\\
[DllImport("kernel32.dll")]
private static extern int Beep(int dwFreq, int dwDuration);
///


The MessageBeep Interop function plays a Wave sound through the soundcard.
There is no need to use MessageBeep via Interop, just use:
\\\
System.Media.SystemSounds.Beep.Play();
///

--
Mick Doherty
http://www.dotnetrix.co.uk/nothing.html
  Rafae replied...
10-Feb-08 02:23 PM
Thank you Mick!!

System.Media.SystemSounds.Beep.Play(); worked just fine. Although I wonder
why Console.Beep(); doesn't beep, there must be some configuration that I
haven't set, or something...

--
Rafael
  Mick Doherty replied...
11-Feb-08 05:19 AM
Hi Rafael,

As I stated, Beep uses the PC Speaker, which is attached to the motherboard
(mainboard),
whereas, MessageBeep plays a wave sound through the soundcard. So
Console.Beep() will only sound if you have a PC Speaker attached to the
motherboard.

If you have a PC Speaker then it may have been disabled.
http://www.computerhope.com/issues/ch000725.htm

--
Mick Doherty
http://www.dotnetrix.co.uk/nothing.html
  RafaelSoteld replied...
13-Feb-08 08:58 AM
Thank you Mick!

I checked in the device manager and the non plug and play Beep device was
not disable, although there's another thing with Motherboard cable that I
have to check.

Again, thank!

--

Rafael Soteldo
help
PS: verwendet wird C# 2.0 C# - German Discussions Windows XP (1) Windows Vista (1) SystemSounds (1) RegistryKey (1) DllImport (1) CharSet (1) IntPtr (1) XP (1) Systemweit bei z.B. Windows Vista unter "Systemsteuerung" -> "Sound" -> Reiter mvps.org / dotnet / faqs / > Hallo Carsten, Zunächst könnte man den Sound (recht brutal) direkt abschalten: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam etc. gezielt angepasst werden, die dann jeweils auch sogar beim Abspielen der Framework-Methoden wie: SystemSounds.Exclamation.Play(); SystemSounds.Beep.Play(); auch wirken. ciao Frank - - Dipl.Inf. Frank Dzaebel [MCP / MVP C#] http: / / Dzaebel
Protection Fault! .NET Framework Hi folks, Consider the following code: [DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall, SetLastError = true)] private static extern int OpenPrinter(string pPrinterName, out IntPtr phPrinter, IntPtr pDefault); [DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall, SetLastError = true)] private static extern int ClosePrinter(IntPtr hPrinter DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall, SetLastError = true)] private static extern int DocumentProperties(IntPtr
RAS_MaxUserData = 200, RAS_MaxReplyMessage = 1024, RAS_MaxDnsSuffix = 256, UNLEN = 256, PWLEN = 256, DNLEN = 15 } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct RASDIALPARAMS { public int dwSize; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)RasFieldSizeConstants.RAS_MaxEntryName +1 RasFieldSizeConstants.DNLEN +1)] public string szDomain; public int dwSubEntry; public IntPtr dwCallbackId ; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct RasEntryName { public int dwSize; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)RasFieldSizeConstants.RAS_MaxEntryName + 1)] public string szEntryName; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct RASCONN { public int dwSize; public IntPtr hrasconn; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int RasFieldSizeConstants.RAS_MaxEntryName + 1))] public string szEntryName; } [DllImport("coredll.dll", CharSet = CharSet.Auto)] public extern static uint RasEnumEntries( string reserved, / / reserved, must be NULL string lpszPhonebook
DllImport could not be found ? .NET Framework Hi All, I need to use this line ( copy from somewhere to create mouse click event ) [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] However, I can't pass complier, the error message is: = > The type oro namespace name 'DllImport' could not be found ( are you missing a using directive or an assembly reference ? ) Best regards, Boki. C# Discussions System.Runtime.InteropServices (1) CallingConvention.StdCall (1) DllImportAttribute (1) CallingConvention (1) DllImport (1) CharSet (1) Wienhold (1) Oro (1) Try adding "using System.Runtime.InteropServices;" to your class, that DllImportAttribute resides in. hth, Kevin Wienhold It works, thanks a lot! :) Best regards, Boki. keywords: DllImport, could, not, be, found, ? description: Hi All, I need to use this line ( copy from