Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net system beep sound on XP

Is it possible to have a vb.net program sound the PC's internal speaker? you know the one that produces C's \a BELL I have tried beep(), but this only produces the error sound on the sound card. I have also tried

<Runtime.InteropServices.DllImport("KERNEL32.DLL", EntryPoint:="Beep", SetLastError:=True, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall)> _
Public Shared Function _
   aBeep(ByVal dwFreq As Integer, ByVal dwDuration As Integer) _
     As Boolean
End Function

With no joy apparently its only good on Vista and above. Any suggestions?

like image 457
Toby Avatar asked Oct 23 '22 02:10

Toby


1 Answers

Using the My namespace in VB.NET, you can get access to audio by going through My.Computer.Audio. This has a Play method with a number of overloads that allow you to pass in a .wav sound by file location or as a Byte array or Stream, but it also has a PlaySystemSound method which takes an enum, one of which is Beep. So the full line to play this sound is:

My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)

No guarantees but as it's part of the .Net framework I think this should work on XP and Vista...

like image 126
PhilPursglove Avatar answered Oct 27 '22 10:10

PhilPursglove