Default Beep

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"?
 
D

Daniel O'Connell [C# MVP]

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.
 
T

Thom Little

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.
 
D

Daniel O'Connell [C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top