title: List and Select Sound Card to Play Sound
body: <p>I have a school bell project coded with Visual Basic 2010 Express. The computer which runs my program has two or more sound cards. First I will list the sound cards to user. User will select the sound card to work. Finally my program will ring the bells on that sound card. Everything is okey for my codes but i can't list the names of sound cards and ring the bell on specified sound card. </p>
  
  <p>I use WMPLib to play music. I have these codes but there becomes an error "the value is not in the expected range". I spotted where the error is in my codes:</p>
  
  <pre><code>    Public Declare Function waveOutGetNumDevs Lib "winmm" () As Integer
      Public Declare Function mciSendCommand Lib "winmm.dll" Alias "mciSendCommandA" (ByVal wDeviceID As Integer, ByVal uMessage As String, ByVal dwParam1 As Integer, ByVal dwParam2 As Object) As Integer
      Public Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Integer, ByVal lpstrBuffer As String, ByVal uLength As Integer) As Integer
      Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
      Public Declare Function mciGetDeviceID Lib "winmm.dll" Alias "mciGetDeviceIDA" (ByVal lpstrName As String) As Integer
  
  Public Const MMSYSERR_NOERROR = 0
      Public Const MCI_SET = &amp;H80D
      Public Const MCI_WAVE_OUTPUT = &amp;H800000
      Public Structure MCI_WAVE_SET_PARMS
          Dim dwCallback As Integer
          Dim dwTimeFormat As Integer
          Dim dwAudio As Integer
          Dim wInput As Integer
          Dim wOutput As Integer
          Dim wFormatTag As Short
          Dim wReserved2 As Short
          Dim nChannels As Short
          Dim wReserved3 As Short
          Dim nSamplesPerSec As Integer
          Dim nAvgBytesPerSec As Integer
          Dim nBlockAlign As Short
          Dim wReserved4 As Short
          Dim wBitsPerSample As Short
          Dim wReserved5 As Short
      End Structure
  
  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
          Dim parms As MCI_WAVE_SET_PARMS
          Dim wDeviceID As Integer
          Dim ret As Integer
  
          parms.wOutput = 0
  
          wDeviceID = mciGetDeviceID("waveaudio")
  
          ' the value is not in the expected range error is here and it spots parms
          ret = mciSendCommand(wDeviceID, MCI_SET, MCI_WAVE_OUTPUT, parms)
  
          If (ret &lt;&gt; MMSYSERR_NOERROR) Then
              Stop
          End If
  
          If ofd.ShowDialog Then
              ret = mciSendString("Open " &amp; Chr(34) &amp; ofd.FileName &amp; Chr(34) &amp; " alias audio", CStr(0), 0, 0)
              ret = mciSendString("Open audio", CStr(0), 0, 0)
          End If
      End Sub
  </code></pre>