Default Beep

  • Thread starter Thread starter Thom Little
  • Start date Start date
T

Thom Little

The following code will produce a sound in C# ...

using System.Runtime.InteropServices;
Beep( 500, 500 );

[DllImport("kernel32.dll")]
private static extern bool Beep( int freq, int dur );

How can I play the sound associated with the System "Default Beep"?
 
Thom Little said:
The following code will produce a sound in C# ...

using System.Runtime.InteropServices;
Beep( 500, 500 );

[DllImport("kernel32.dll")]
private static extern bool Beep( int freq, int dur );

How can I play the sound associated with the System "Default Beep"?

Best I can tell, you need to use PlaySound. This article describes its use,
converting it to a pinvoke shouldn't be too difficult:
http://msdn.microsoft.com/library/d..._playing_sounds_specified_in_the_registry.asp

I believe SystemAsterisk is the name of the default windows beep.
 
Thanks for the lead. Requesting any sound that is not defined gives the
Default Beep. The solution is ...

using System.Runtime.InteropServices ;

[DllImport("winmm.dll")]
public static extern long PlaySound( string lpszName, long hModule, long
dwFlags );

PlaySound( " ", 0, 0 );

Is it safe to assume that every Windows machines has winmm.dll installed or
should the PlaySound call be protected with a Try/Catch?

--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
--

Daniel O'Connell said:
Thom Little said:
The following code will produce a sound in C# ...

using System.Runtime.InteropServices;
Beep( 500, 500 );

[DllImport("kernel32.dll")]
private static extern bool Beep( int freq, int dur );

How can I play the sound associated with the System "Default Beep"?

Best I can tell, you need to use PlaySound. This article describes its
use, converting it to a pinvoke shouldn't be too difficult:
http://msdn.microsoft.com/library/d..._playing_sounds_specified_in_the_registry.asp

I believe SystemAsterisk is the name of the default windows beep.
 
Thom Little said:
Thanks for the lead. Requesting any sound that is not defined gives the
Default Beep. The solution is ...

using System.Runtime.InteropServices ;

[DllImport("winmm.dll")]
public static extern long PlaySound( string lpszName, long hModule, long
dwFlags );

PlaySound( " ", 0, 0 );

Is it safe to assume that every Windows machines has winmm.dll installed
or should the PlaySound call be protected with a Try/Catch?

I think WiMM is pretty safe to rely on.
 
Back
Top