?
Solved

HOW to select "MICROPHONE" as recording input device

Posted on 2005-04-07
12
Medium Priority
?
1,993 Views
Last Modified: 2008-08-26
I need a sample Visual Basic application with 3 buttons:

Button 1) checks what is the current recording input device

Button 2) selects the microphone as the recording input device

Button 3) restores back the initial recording input device if button 2 was clicked

A TOP-DOG Expert will be able to give me code on all 3 buttons.  However, I am mainly interested in Button 2.
I will only give points if you provide me with full working sample code. Please do not send me links.

Thanks.



0
Comment
Question by:frankmorrison
12 Comments
 
LVL 5

Expert Comment

by:Rubyn
ID: 13731020
Option Explicit

Private Const MAXPNAMELEN = 32  '  max product name length (including NULL)

Private Const MIXER_GETCONTROLDETAILSF_LISTTEXT = &H1&
Private Const MIXER_GETCONTROLDETAILSF_QUERYMASK = &HF&
Private Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&

Private Const MIXER_GETLINECONTROLSF_ALL = &H0&
Private Const MIXER_GETLINECONTROLSF_ONEBYID = &H1&
Private Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
Private Const MIXER_GETLINECONTROLSF_QUERYMASK = &HF&

Private Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
Private Const MIXER_GETLINEINFOF_DESTINATION = &H0&
Private Const MIXER_GETLINEINFOF_LINEID = &H2&
Private Const MIXER_GETLINEINFOF_QUERYMASK = &HF&
Private Const MIXER_GETLINEINFOF_SOURCE = &H1&
Private Const MIXER_GETLINEINFOF_TARGETTYPE = &H4&

Private Const MIXER_LONG_NAME_CHARS = 64
Private Const MIXER_SHORT_NAME_CHARS = 16

Private Const MIXER_OBJECTF_AUX = &H50000000
Private Const MIXER_OBJECTF_HANDLE = &H80000000
Private Const MIXER_OBJECTF_MIDIIN = &H40000000
Private Const MIXER_OBJECTF_MIDIOUT = &H30000000
Private Const MIXER_OBJECTF_MIXER = &H0&
Private Const MIXER_OBJECTF_WAVEIN = &H20000000
Private Const MIXER_OBJECTF_WAVEOUT = &H10000000
Private Const MIXER_OBJECTF_HMIDIIN = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIIN)
Private Const MIXER_OBJECTF_HMIDIOUT = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)
Private Const MIXER_OBJECTF_HMIXER = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)
Private Const MIXER_OBJECTF_HWAVEIN = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)
Private Const MIXER_OBJECTF_HWAVEOUT = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)

Private Const MIXER_SETCONTROLDETAILSF_CUSTOM = &H1&
Private Const MIXER_SETCONTROLDETAILSF_QUERYMASK = &HF&
Private Const MIXER_SETCONTROLDETAILSF_VALUE = &H0&

Private Const MIXERCONTROL_CONTROLF_DISABLED = &H80000000
Private Const MIXERCONTROL_CONTROLF_MULTIPLE = &H2&
Private Const MIXERCONTROL_CONTROLF_UNIFORM = &H1&

Private Const MIXERCONTROL_CT_CLASS_CUSTOM = &H0&
Private Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
Private Const MIXERCONTROL_CT_CLASS_LIST = &H70000000
Private Const MIXERCONTROL_CT_CLASS_MASK = &HF0000000
Private Const MIXERCONTROL_CT_CLASS_METER = &H10000000
Private Const MIXERCONTROL_CT_CLASS_NUMBER = &H30000000
Private Const MIXERCONTROL_CT_CLASS_SLIDER = &H40000000
Private Const MIXERCONTROL_CT_CLASS_SWITCH = &H20000000
Private Const MIXERCONTROL_CT_CLASS_TIME = &H60000000
Private Const MIXERCONTROL_CT_SC_LIST_MULTIPLE = &H1000000
Private Const MIXERCONTROL_CT_SC_LIST_SINGLE = &H0&
Private Const MIXERCONTROL_CT_SC_METER_POLLED = &H0&
Private Const MIXERCONTROL_CT_SC_SWITCH_BOOLEAN = &H0&
Private Const MIXERCONTROL_CT_SC_SWITCH_BUTTON = &H1000000
Private Const MIXERCONTROL_CT_SC_TIME_MICROSECS = &H0&
Private Const MIXERCONTROL_CT_SC_TIME_MILLISECS = &H1000000
Private Const MIXERCONTROL_CT_SUBCLASS_MASK = &HF000000
Private Const MIXERCONTROL_CT_UNITS_BOOLEAN = &H10000
Private Const MIXERCONTROL_CT_UNITS_CUSTOM = &H0&
Private Const MIXERCONTROL_CT_UNITS_DECIBELS = &H40000 '  in 10ths
Private Const MIXERCONTROL_CT_UNITS_MASK = &HFF0000
Private Const MIXERCONTROL_CT_UNITS_PERCENT = &H50000 '  in 10ths
Private Const MIXERCONTROL_CT_UNITS_SIGNED = &H20000
Private Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000
Private Const MIXERCONTROL_CONTROLTYPE_FADER = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_SLIDER = (MIXERCONTROL_CT_CLASS_SLIDER Or MIXERCONTROL_CT_UNITS_SIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_SIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_SIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_SINGLESELECT = (MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_SC_LIST_SINGLE Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT = (MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_SC_LIST_MULTIPLE Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_BASS = (MIXERCONTROL_CONTROLTYPE_FADER + 2)
Private Const MIXERCONTROL_CONTROLTYPE_BOOLEAN = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_SC_SWITCH_BOOLEAN Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_BOOLEANMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_BUTTON = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_SC_SWITCH_BUTTON Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_CUSTOM = (MIXERCONTROL_CT_CLASS_CUSTOM Or MIXERCONTROL_CT_UNITS_CUSTOM)
Private Const MIXERCONTROL_CONTROLTYPE_DECIBELS = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_DECIBELS)
Private Const MIXERCONTROL_CONTROLTYPE_EQUALIZER = (MIXERCONTROL_CONTROLTYPE_FADER + 4)
Private Const MIXERCONTROL_CONTROLTYPE_LOUDNESS = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 4)
Private Const MIXERCONTROL_CONTROLTYPE_MICROTIME = (MIXERCONTROL_CT_CLASS_TIME Or MIXERCONTROL_CT_SC_TIME_MICROSECS Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_MILLITIME = (MIXERCONTROL_CT_CLASS_TIME Or MIXERCONTROL_CT_SC_TIME_MILLISECS Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_MIXER = (MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT + 1)
Private Const MIXERCONTROL_CONTROLTYPE_MONO = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 3)
Private Const MIXERCONTROL_CONTROLTYPE_MUTE = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 2)
Private Const MIXERCONTROL_CONTROLTYPE_MUX = (MIXERCONTROL_CONTROLTYPE_SINGLESELECT + 1)
Private Const MIXERCONTROL_CONTROLTYPE_ONOFF = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 1)
Private Const MIXERCONTROL_CONTROLTYPE_PAN = (MIXERCONTROL_CONTROLTYPE_SLIDER + 1)
Private Const MIXERCONTROL_CONTROLTYPE_PEAKMETER = (MIXERCONTROL_CONTROLTYPE_SIGNEDMETER + 1)
Private Const MIXERCONTROL_CONTROLTYPE_PERCENT = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_PERCENT)
Private Const MIXERCONTROL_CONTROLTYPE_QSOUNDPAN = (MIXERCONTROL_CONTROLTYPE_SLIDER + 2)
Private Const MIXERCONTROL_CONTROLTYPE_SIGNED = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_SIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_STEREOENH = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 5)
Private Const MIXERCONTROL_CONTROLTYPE_TREBLE = (MIXERCONTROL_CONTROLTYPE_FADER + 3)
Private Const MIXERCONTROL_CONTROLTYPE_UNSIGNED = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1)

Private Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&
Private Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
Private Const MIXERLINE_COMPONENTTYPE_DST_DIGITAL = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 1)
Private Const MIXERLINE_COMPONENTTYPE_DST_HEADPHONES = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 5)
Private Const MIXERLINE_COMPONENTTYPE_DST_LAST = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 8)
Private Const MIXERLINE_COMPONENTTYPE_DST_LINE = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 2)
Private Const MIXERLINE_COMPONENTTYPE_DST_MONITOR = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 3)
Private Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
Private Const MIXERLINE_COMPONENTTYPE_DST_TELEPHONE = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 6)
Private Const MIXERLINE_COMPONENTTYPE_DST_UNDEFINED = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 0)
Private Const MIXERLINE_COMPONENTTYPE_DST_VOICEIN = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 8)
Private Const MIXERLINE_COMPONENTTYPE_DST_WAVEIN = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 7)
Private Const MIXERLINE_COMPONENTTYPE_SRC_ANALOG = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 10)
Private Const MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 9)
Private Const MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 5)
Private Const MIXERLINE_COMPONENTTYPE_SRC_DIGITAL = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 1)
Private Const MIXERLINE_COMPONENTTYPE_SRC_LAST = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 10)
Private Const MIXERLINE_COMPONENTTYPE_SRC_LINE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2)
Private Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3)
Private Const MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 7)
Private Const MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 4)
Private Const MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 6)
Private Const MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 0)
Private Const MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 8)
Private Const MIXERLINE_LINEF_ACTIVE = &H1&
Private Const MIXERLINE_LINEF_DISCONNECTED = &H8000&
Private Const MIXERLINE_LINEF_SOURCE = &H80000000
Private Const MIXERLINE_TARGETTYPE_AUX = 5
Private Const MIXERLINE_TARGETTYPE_MIDIIN = 4
Private Const MIXERLINE_TARGETTYPE_MIDIOUT = 3
Private Const MIXERLINE_TARGETTYPE_UNDEFINED = 0
Private Const MIXERLINE_TARGETTYPE_WAVEIN = 2
Private Const MIXERLINE_TARGETTYPE_WAVEOUT = 1
Private Const MIXERR_BASE = 1024
Private Const MIXERR_INVALCONTROL = (MIXERR_BASE + 1)
Private Const MIXERR_INVALLINE = (MIXERR_BASE + 0)
Private Const MIXERR_INVALVALUE = (MIXERR_BASE + 2)
Private Const MIXERR_LASTERROR = (MIXERR_BASE + 2)

Private Type MIXERCAPS
        wMid As Integer                   '  manufacturer id
        wPid As Integer                   '  product id
        vDriverVersion As Long            '  version of the driver
        szPname As String * MAXPNAMELEN   '  product name
        fdwSupport As Long             '  misc. support bits
        cDestinations As Long          '  count of destinations
End Type
Private Type MIXERCONTROL
        cbStruct As Long           '  size in Byte of MIXERCONTROL
        dwControlID As Long        '  unique control id for mixer device
        dwControlType As Long      '  MIXERCONTROL_CONTROLTYPE_xxx
        fdwControl As Long         '  MIXERCONTROL_CONTROLF_xxx
        cMultipleItems As Long     '  if MIXERCONTROL_CONTROLF_MULTIPLE set
        szShortName(MIXER_SHORT_NAME_CHARS / 2 - 1) As Integer
        szName(MIXER_LONG_NAME_CHARS / 2 - 1) As Integer
        Bounds(5) As Long     '  Longest member of the Bounds union
        Metrics(5) As Long    '  Longest member of the Metrics union
End Type
Private Type MIXERCONTROLDETAILS
        cbStruct As Long       '  size in Byte of MIXERCONTROLDETAILS
        dwControlID As Long    '  control id to get/set details on
        cChannels As Long      '  number of channels in paDetails array
        item As Long                           ' hwndOwner or cMultipleItems
        cbDetails As Long      '  size of _one_ details_XX struct
        paDetails As Long      '  pointer to array of details_XX structs
End Type
Private Type Target    ' for use in MIXERLINE and others (embedded structure)
       
        dwType As Long                 '  MIXERLINE_TARGETTYPE_xxxx
        dwDeviceID As Long             '  target device ID of device type
        wMid As Integer                   '  of target device
        wPid As Integer                   '       "
        vDriverVersion As Long            '       "
        szPname As String * MAXPNAMELEN
End Type
Private Type MIXERLINE
        cbStruct As Long               '  size of MIXERLINE structure
        dwDestination As Long          '  zero based destination index
        dwSource As Long               '  zero based source index (if source)
        dwLineID As Long               '  unique line id for mixer device
        fdwLine As Long                '  state/information about line
        dwUser As Long                 '  driver specific information
        dwComponentType As Long        '  component type line connects to
        cChannels As Long              '  number of channels line supports
        cConnections As Long           '  number of connections (possible)
        cControls As Long              '  number of controls at this line
        szShortName As String * MIXER_SHORT_NAME_CHARS
        szName As String * MIXER_LONG_NAME_CHARS
        tTarget As Target
End Type
Private Type MIXERLINECONTROLS
        cbStruct As Long       '  size in Byte of MIXERLINECONTROLS
        dwLineID As Long       '  line id (from MIXERLINE.dwLineID)
                                             '  MIXER_GETLINECONTROLSF_ONEBYID or
        dwControl As Long  '  MIXER_GETLINECONTROLSF_ONEBYTYPE
        cControls As Long      '  count of controls pmxctrl points to
        cbmxctrl As Long       '  size in Byte of _one_ MIXERCONTROL
        pamxctrl As Long       '  pointer to first MIXERCONTROL array
End Type

Private Declare Function mixerClose Lib "winmm.dll" (ByVal hmx As Long) As Long
Private Declare Function mixerGetControlDetails Lib "winmm.dll" Alias "mixerGetControlDetailsA" (ByVal hmxobj As Long, pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long
Private Declare Function mixerGetDevCaps Lib "winmm.dll" Alias "mixerGetDevCapsA" (ByVal uMxId As Long, ByVal pmxcaps As MIXERCAPS, ByVal cbmxcaps As Long) As Long
Private Declare Function mixerGetID Lib "winmm.dll" (ByVal hmxobj As Long, pumxID As Long, ByVal fdwId As Long) As Long
Private Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (ByVal hmxobj As Long, pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Long) As Long
Private Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Long, pmxl As MIXERLINE, ByVal fdwInfo As Long) As Long
Private Declare Function mixerGetNumDevs Lib "winmm.dll" () As Long
Private Declare Function mixerMessage Lib "winmm.dll" (ByVal hmx As Long, ByVal uMsg As Long, ByVal dwParam1 As Long, ByVal dwParam2 As Long) As Long
Private Declare Function mixerOpen Lib "winmm.dll" (phmx As Long, ByVal uMxId As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal fdwOpen As Long) As Long
Private Declare Function mixerSetControlDetails Lib "winmm.dll" (ByVal hmxobj As Long, pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, ByVal Source As Long, ByVal length As Long)

Public Function SelectMicrophone(DeviceID As Long, Optional sError As String) As Boolean
Dim pmxcaps As MIXERCAPS, pmxl As MIXERLINE, pmxlc As MIXERLINECONTROLS, pmxc() As MIXERCONTROL, pmxcd As MIXERCONTROLDETAILS, pdata() As Long
Dim rc As Long, Index As Long, Text(63) As Byte, Msg As String, Str1 As String
Dim MicIndex As Long
On Error GoTo Exception
    'Get WaveIn Destination Number
    Let pmxl.cbStruct = Len(pmxl)
    Let pmxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN
    Let rc = mixerGetLineInfo(DeviceID, pmxl, MIXER_OBJECTF_WAVEIN Or MIXER_GETLINEINFOF_COMPONENTTYPE)
    If rc <> 0 Then GoTo Exception 'Error Trap
    'Check For Microphone Source in that distination
    For Index = 0 To pmxl.cConnections - 1
        Let pmxl.dwSource = Index
        Let rc = mixerGetLineInfo(DeviceID, pmxl, MIXER_GETLINEINFOF_SOURCE)
        If rc <> 0 Then GoTo Exception 'Error Trap
        If pmxl.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE Then MicIndex = Index:  Exit For
    Next
    'Adjust Recording Level of that Microphone
    ReDim pmxc(pmxl.cControls - 1)
    Let pmxlc.cbStruct = Len(pmxlc)
    Let pmxlc.dwLineID = pmxl.dwLineID
    Let pmxlc.cControls = pmxl.cControls
    Let pmxlc.cbmxctrl = Len(pmxc(0))
    Let pmxlc.pamxctrl = VarPtr(pmxc(0))
    Let rc = mixerGetLineControls(DeviceID, pmxlc, MIXER_OBJECTF_WAVEIN Or MIXER_GETLINECONTROLSF_ALL)
    If rc <> 0 Then GoTo Exception 'Error Trap
    For Index = LBound(pmxc) To UBound(pmxc)
        'Check its fader control
        If pmxc(Index).dwControlType = (pmxc(Index).dwControlType Or MIXERCONTROL_CT_CLASS_FADER) Then
            ReDim pdata(0) As Long
            Let pmxcd.cbStruct = Len(pmxcd)
            Let pmxcd.cChannels = 1
            Let pmxcd.dwControlID = pmxc(Index).dwControlID
            Let pmxcd.cbDetails = Len(pdata(0))
            Let pmxcd.paDetails = VarPtr(pdata(0))
            Let pdata(0) = pmxc(Index).Bounds(1) * 0.75 'Max
            Let rc = mixerSetControlDetails(DeviceID, pmxcd, MIXER_GETCONTROLDETAILSF_VALUE)
            If rc <> 0 Then GoTo Exception 'Error Trap
        'Check Boost
        ElseIf pmxc(Index).dwControlType = (pmxc(Index).dwControlType Or MIXERCONTROL_CONTROLTYPE_BOOLEAN) Then
            ReDim pdata(0) As Long
            Let pmxcd.cbStruct = Len(pmxcd)
            Let pmxcd.cChannels = 1
            Let pmxcd.dwControlID = pmxc(Index).dwControlID
            Let pmxcd.cbDetails = Len(pdata(0))
            Let pmxcd.paDetails = VarPtr(pdata(0))
            Let pdata(0) = 1 'On
            Let rc = mixerSetControlDetails(DeviceID, pmxcd, MIXER_GETCONTROLDETAILSF_VALUE)
            If rc <> 0 Then GoTo Exception 'Error Trap
        End If
    Next
   
    Let pmxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN
    Let rc = mixerGetLineInfo(DeviceID, pmxl, MIXER_OBJECTF_WAVEIN Or MIXER_GETLINEINFOF_COMPONENTTYPE)
   
    ReDim pmxc(pmxl.cControls - 1)
    Let pmxlc.dwLineID = pmxl.dwLineID
    Let pmxlc.cControls = pmxl.cControls
    Let pmxlc.pamxctrl = VarPtr(pmxc(0))
    Let rc = mixerGetLineControls(DeviceID, pmxlc, MIXER_OBJECTF_WAVEIN Or MIXER_GETLINECONTROLSF_ALL)
    If rc <> 0 Then GoTo Exception 'Error Trap
    For Index = LBound(pmxc) To UBound(pmxc)
        'Check its multiple select
        If pmxc(Index).dwControlType = (pmxc(Index).dwControlType Or MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_UNITS_BOOLEAN) Then
            ReDim pdata(pmxc(Index).cMultipleItems - 1) As Long
            Let pmxcd.dwControlID = pmxc(Index).dwControlID
            Let pmxcd.item = pmxc(Index).cMultipleItems
            Let pmxcd.paDetails = VarPtr(pdata(0))
            Let pdata(pmxcd.item - MicIndex - 1) = 1
            Let rc = mixerSetControlDetails(DeviceID, pmxcd, MIXER_GETCONTROLDETAILSF_VALUE)
            If rc <> 0 Then GoTo Exception 'Error Trap
        End If
    Next
Let SelectMicrophone = True
Exit Function
Exception:
End Function
0
 
LVL 5

Expert Comment

by:Rubyn
ID: 13731044
Paste the above code in a module and in command2 paste Call SelectMicrophone(0)
0
 
LVL 1

Author Comment

by:frankmorrison
ID: 13741124
Rubyn,

I tried your code, but all it does is increase the volume of recording input microphone.  But it does NOT select it.  Example:  I have recording microphone volume to lowest and "line in" selected as the default recording device. When command2 is pressed, "line in" remains as the default recording device and microphone's volume increases to 85%.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:frankmorrison
ID: 13741144
Rubyn,

I tested your code a little more.... Actually, it IS selecting the "Line In" as the default recording device and NOT the microphone. So, your code may just need a small fine tunning....
0
 
LVL 5

Accepted Solution

by:
Rubyn earned 2000 total points
ID: 13741863
Option Explicit

Private Const MAXPNAMELEN = 32  '  max product name length (including NULL)

Private Const MIXER_GETCONTROLDETAILSF_LISTTEXT = &H1&
Private Const MIXER_GETCONTROLDETAILSF_QUERYMASK = &HF&
Private Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&

Private Const MIXER_GETLINECONTROLSF_ALL = &H0&
Private Const MIXER_GETLINECONTROLSF_ONEBYID = &H1&
Private Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
Private Const MIXER_GETLINECONTROLSF_QUERYMASK = &HF&

Private Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
Private Const MIXER_GETLINEINFOF_DESTINATION = &H0&
Private Const MIXER_GETLINEINFOF_LINEID = &H2&
Private Const MIXER_GETLINEINFOF_QUERYMASK = &HF&
Private Const MIXER_GETLINEINFOF_SOURCE = &H1&
Private Const MIXER_GETLINEINFOF_TARGETTYPE = &H4&

Private Const MIXER_LONG_NAME_CHARS = 64
Private Const MIXER_SHORT_NAME_CHARS = 16

Private Const MIXER_OBJECTF_AUX = &H50000000
Private Const MIXER_OBJECTF_HANDLE = &H80000000
Private Const MIXER_OBJECTF_MIDIIN = &H40000000
Private Const MIXER_OBJECTF_MIDIOUT = &H30000000
Private Const MIXER_OBJECTF_MIXER = &H0&
Private Const MIXER_OBJECTF_WAVEIN = &H20000000
Private Const MIXER_OBJECTF_WAVEOUT = &H10000000
Private Const MIXER_OBJECTF_HMIDIIN = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIIN)
Private Const MIXER_OBJECTF_HMIDIOUT = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)
Private Const MIXER_OBJECTF_HMIXER = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)
Private Const MIXER_OBJECTF_HWAVEIN = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)
Private Const MIXER_OBJECTF_HWAVEOUT = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)

Private Const MIXER_SETCONTROLDETAILSF_CUSTOM = &H1&
Private Const MIXER_SETCONTROLDETAILSF_QUERYMASK = &HF&
Private Const MIXER_SETCONTROLDETAILSF_VALUE = &H0&

Private Const MIXERCONTROL_CONTROLF_DISABLED = &H80000000
Private Const MIXERCONTROL_CONTROLF_MULTIPLE = &H2&
Private Const MIXERCONTROL_CONTROLF_UNIFORM = &H1&

Private Const MIXERCONTROL_CT_CLASS_CUSTOM = &H0&
Private Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
Private Const MIXERCONTROL_CT_CLASS_LIST = &H70000000
Private Const MIXERCONTROL_CT_CLASS_MASK = &HF0000000
Private Const MIXERCONTROL_CT_CLASS_METER = &H10000000
Private Const MIXERCONTROL_CT_CLASS_NUMBER = &H30000000
Private Const MIXERCONTROL_CT_CLASS_SLIDER = &H40000000
Private Const MIXERCONTROL_CT_CLASS_SWITCH = &H20000000
Private Const MIXERCONTROL_CT_CLASS_TIME = &H60000000
Private Const MIXERCONTROL_CT_SC_LIST_MULTIPLE = &H1000000
Private Const MIXERCONTROL_CT_SC_LIST_SINGLE = &H0&
Private Const MIXERCONTROL_CT_SC_METER_POLLED = &H0&
Private Const MIXERCONTROL_CT_SC_SWITCH_BOOLEAN = &H0&
Private Const MIXERCONTROL_CT_SC_SWITCH_BUTTON = &H1000000
Private Const MIXERCONTROL_CT_SC_TIME_MICROSECS = &H0&
Private Const MIXERCONTROL_CT_SC_TIME_MILLISECS = &H1000000
Private Const MIXERCONTROL_CT_SUBCLASS_MASK = &HF000000
Private Const MIXERCONTROL_CT_UNITS_BOOLEAN = &H10000
Private Const MIXERCONTROL_CT_UNITS_CUSTOM = &H0&
Private Const MIXERCONTROL_CT_UNITS_DECIBELS = &H40000 '  in 10ths
Private Const MIXERCONTROL_CT_UNITS_MASK = &HFF0000
Private Const MIXERCONTROL_CT_UNITS_PERCENT = &H50000 '  in 10ths
Private Const MIXERCONTROL_CT_UNITS_SIGNED = &H20000
Private Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000
Private Const MIXERCONTROL_CONTROLTYPE_FADER = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_SLIDER = (MIXERCONTROL_CT_CLASS_SLIDER Or MIXERCONTROL_CT_UNITS_SIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_SIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_SIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_SINGLESELECT = (MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_SC_LIST_SINGLE Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT = (MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_SC_LIST_MULTIPLE Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_BASS = (MIXERCONTROL_CONTROLTYPE_FADER + 2)
Private Const MIXERCONTROL_CONTROLTYPE_BOOLEAN = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_SC_SWITCH_BOOLEAN Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_BOOLEANMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_BUTTON = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_SC_SWITCH_BUTTON Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_CUSTOM = (MIXERCONTROL_CT_CLASS_CUSTOM Or MIXERCONTROL_CT_UNITS_CUSTOM)
Private Const MIXERCONTROL_CONTROLTYPE_DECIBELS = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_DECIBELS)
Private Const MIXERCONTROL_CONTROLTYPE_EQUALIZER = (MIXERCONTROL_CONTROLTYPE_FADER + 4)
Private Const MIXERCONTROL_CONTROLTYPE_LOUDNESS = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 4)
Private Const MIXERCONTROL_CONTROLTYPE_MICROTIME = (MIXERCONTROL_CT_CLASS_TIME Or MIXERCONTROL_CT_SC_TIME_MICROSECS Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_MILLITIME = (MIXERCONTROL_CT_CLASS_TIME Or MIXERCONTROL_CT_SC_TIME_MILLISECS Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_MIXER = (MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT + 1)
Private Const MIXERCONTROL_CONTROLTYPE_MONO = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 3)
Private Const MIXERCONTROL_CONTROLTYPE_MUTE = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 2)
Private Const MIXERCONTROL_CONTROLTYPE_MUX = (MIXERCONTROL_CONTROLTYPE_SINGLESELECT + 1)
Private Const MIXERCONTROL_CONTROLTYPE_ONOFF = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 1)
Private Const MIXERCONTROL_CONTROLTYPE_PAN = (MIXERCONTROL_CONTROLTYPE_SLIDER + 1)
Private Const MIXERCONTROL_CONTROLTYPE_PEAKMETER = (MIXERCONTROL_CONTROLTYPE_SIGNEDMETER + 1)
Private Const MIXERCONTROL_CONTROLTYPE_PERCENT = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_PERCENT)
Private Const MIXERCONTROL_CONTROLTYPE_QSOUNDPAN = (MIXERCONTROL_CONTROLTYPE_SLIDER + 2)
Private Const MIXERCONTROL_CONTROLTYPE_SIGNED = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_SIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_STEREOENH = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 5)
Private Const MIXERCONTROL_CONTROLTYPE_TREBLE = (MIXERCONTROL_CONTROLTYPE_FADER + 3)
Private Const MIXERCONTROL_CONTROLTYPE_UNSIGNED = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1)

Private Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&
Private Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
Private Const MIXERLINE_COMPONENTTYPE_DST_DIGITAL = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 1)
Private Const MIXERLINE_COMPONENTTYPE_DST_HEADPHONES = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 5)
Private Const MIXERLINE_COMPONENTTYPE_DST_LAST = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 8)
Private Const MIXERLINE_COMPONENTTYPE_DST_LINE = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 2)
Private Const MIXERLINE_COMPONENTTYPE_DST_MONITOR = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 3)
Private Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
Private Const MIXERLINE_COMPONENTTYPE_DST_TELEPHONE = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 6)
Private Const MIXERLINE_COMPONENTTYPE_DST_UNDEFINED = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 0)
Private Const MIXERLINE_COMPONENTTYPE_DST_VOICEIN = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 8)
Private Const MIXERLINE_COMPONENTTYPE_DST_WAVEIN = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 7)
Private Const MIXERLINE_COMPONENTTYPE_SRC_ANALOG = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 10)
Private Const MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 9)
Private Const MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 5)
Private Const MIXERLINE_COMPONENTTYPE_SRC_DIGITAL = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 1)
Private Const MIXERLINE_COMPONENTTYPE_SRC_LAST = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 10)
Private Const MIXERLINE_COMPONENTTYPE_SRC_LINE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2)
Private Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3)
Private Const MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 7)
Private Const MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 4)
Private Const MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 6)
Private Const MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 0)
Private Const MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 8)
Private Const MIXERLINE_LINEF_ACTIVE = &H1&
Private Const MIXERLINE_LINEF_DISCONNECTED = &H8000&
Private Const MIXERLINE_LINEF_SOURCE = &H80000000
Private Const MIXERLINE_TARGETTYPE_AUX = 5
Private Const MIXERLINE_TARGETTYPE_MIDIIN = 4
Private Const MIXERLINE_TARGETTYPE_MIDIOUT = 3
Private Const MIXERLINE_TARGETTYPE_UNDEFINED = 0
Private Const MIXERLINE_TARGETTYPE_WAVEIN = 2
Private Const MIXERLINE_TARGETTYPE_WAVEOUT = 1
Private Const MIXERR_BASE = 1024
Private Const MIXERR_INVALCONTROL = (MIXERR_BASE + 1)
Private Const MIXERR_INVALLINE = (MIXERR_BASE + 0)
Private Const MIXERR_INVALVALUE = (MIXERR_BASE + 2)
Private Const MIXERR_LASTERROR = (MIXERR_BASE + 2)

Private Type MIXERCONTROLDETAILS_LISTTEXT
        dwParam1 As Long
        dwParam2 As Long
        szName As Long ' String * MIXER_LONG_NAME_CHARS
End Type

Private Type MIXERCAPS
        wMid As Integer                   '  manufacturer id
        wPid As Integer                   '  product id
        vDriverVersion As Long            '  version of the driver
        szPname As String * MAXPNAMELEN   '  product name
        fdwSupport As Long             '  misc. support bits
        cDestinations As Long          '  count of destinations
End Type
Private Type MIXERCONTROL
        cbStruct As Long           '  size in Byte of MIXERCONTROL
        dwControlID As Long        '  unique control id for mixer device
        dwControlType As Long      '  MIXERCONTROL_CONTROLTYPE_xxx
        fdwControl As Long         '  MIXERCONTROL_CONTROLF_xxx
        cMultipleItems As Long     '  if MIXERCONTROL_CONTROLF_MULTIPLE set
        szShortName(MIXER_SHORT_NAME_CHARS / 2 - 1) As Integer
        szName(MIXER_LONG_NAME_CHARS / 2 - 1) As Integer
        Bounds(5) As Long     '  Longest member of the Bounds union
        Metrics(5) As Long    '  Longest member of the Metrics union
End Type
Private Type MIXERCONTROLDETAILS
        cbStruct As Long       '  size in Byte of MIXERCONTROLDETAILS
        dwControlID As Long    '  control id to get/set details on
        cChannels As Long      '  number of channels in paDetails array
        item As Long                           ' hwndOwner or cMultipleItems
        cbDetails As Long      '  size of _one_ details_XX struct
        paDetails As Long      '  pointer to array of details_XX structs
End Type
Private Type Target    ' for use in MIXERLINE and others (embedded structure)
       
        dwType As Long                 '  MIXERLINE_TARGETTYPE_xxxx
        dwDeviceID As Long             '  target device ID of device type
        wMid As Integer                   '  of target device
        wPid As Integer                   '       "
        vDriverVersion As Long            '       "
        szPname As String * MAXPNAMELEN
End Type
Private Type MIXERLINE
        cbStruct As Long               '  size of MIXERLINE structure
        dwDestination As Long          '  zero based destination index
        dwSource As Long               '  zero based source index (if source)
        dwLineID As Long               '  unique line id for mixer device
        fdwLine As Long                '  state/information about line
        dwUser As Long                 '  driver specific information
        dwComponentType As Long        '  component type line connects to
        cChannels As Long              '  number of channels line supports
        cConnections As Long           '  number of connections (possible)
        cControls As Long              '  number of controls at this line
        szShortName As String * MIXER_SHORT_NAME_CHARS
        szName As String * MIXER_LONG_NAME_CHARS
        tTarget As Target
End Type
Private Type MIXERLINECONTROLS
        cbStruct As Long       '  size in Byte of MIXERLINECONTROLS
        dwLineID As Long       '  line id (from MIXERLINE.dwLineID)
                                             '  MIXER_GETLINECONTROLSF_ONEBYID or
        dwControl As Long  '  MIXER_GETLINECONTROLSF_ONEBYTYPE
        cControls As Long      '  count of controls pmxctrl points to
        cbmxctrl As Long       '  size in Byte of _one_ MIXERCONTROL
        pamxctrl As Long       '  pointer to first MIXERCONTROL array
End Type

Private Declare Function mixerClose Lib "winmm.dll" (ByVal hmx As Long) As Long
Private Declare Function mixerGetControlDetails Lib "winmm.dll" Alias "mixerGetControlDetailsA" (ByVal hmxobj As Long, pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long
Private Declare Function mixerGetDevCaps Lib "winmm.dll" Alias "mixerGetDevCapsA" (ByVal uMxId As Long, ByVal pmxcaps As MIXERCAPS, ByVal cbmxcaps As Long) As Long
Private Declare Function mixerGetID Lib "winmm.dll" (ByVal hmxobj As Long, pumxID As Long, ByVal fdwId As Long) As Long
Private Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (ByVal hmxobj As Long, pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Long) As Long
Private Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Long, pmxl As MIXERLINE, ByVal fdwInfo As Long) As Long
Private Declare Function mixerGetNumDevs Lib "winmm.dll" () As Long
Private Declare Function mixerMessage Lib "winmm.dll" (ByVal hmx As Long, ByVal uMsg As Long, ByVal dwParam1 As Long, ByVal dwParam2 As Long) As Long
Private Declare Function mixerOpen Lib "winmm.dll" (phmx As Long, ByVal uMxId As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal fdwOpen As Long) As Long
Private Declare Function mixerSetControlDetails Lib "winmm.dll" (ByVal hmxobj As Long, pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, ByVal Source As Long, ByVal length As Long)

Public Function SelectMicrophone(DeviceID As Long, Optional sError As String) As Boolean
Dim pmxl As MIXERLINE, pmxlc As MIXERLINECONTROLS, pmxc As MIXERCONTROL, pmxcd As MIXERCONTROLDETAILS, mcdlt() As MIXERCONTROLDETAILS_LISTTEXT, mcdb() As Long
Dim rc As Long, Index As Long
On Error GoTo Exception
    'Get WaveIn Destination Line ID
    Let pmxl.cbStruct = Len(pmxl)
    Let pmxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN
    Let rc = mixerGetLineInfo(DeviceID, pmxl, MIXER_GETLINEINFOF_COMPONENTTYPE)
    If rc <> 0 Then GoTo Exception 'Error Trap
   
    'Get Control ID with MIXER
    Let pmxlc.cbStruct = Len(pmxlc)
    Let pmxlc.dwLineID = pmxl.dwLineID
    Let pmxlc.dwControl = MIXERCONTROL_CONTROLTYPE_MIXER
    Let pmxlc.cControls = pmxl.cControls
    Let pmxlc.cbmxctrl = Len(pmxc)
    Let pmxlc.pamxctrl = VarPtr(pmxc)
    Let rc = mixerGetLineControls(DeviceID, pmxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
    If rc <> 0 Then
        'Get Control ID
        Let pmxlc.dwControl = MIXERCONTROL_CONTROLTYPE_MUX
        Let rc = mixerGetLineControls(DeviceID, pmxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
        If rc <> 0 Then GoTo Exception 'Error Trap
    End If

    'Get Control Details
    ReDim mcdlt(pmxc.cMultipleItems - 1)
    Let pmxcd.cbStruct = Len(pmxcd)
    Let pmxcd.cChannels = 1
    Let pmxcd.dwControlID = pmxc.dwControlID
    Let pmxcd.item = pmxc.cMultipleItems
    Let pmxcd.cbDetails = Len(mcdlt(0))
    Let pmxcd.paDetails = VarPtr(mcdlt(0))
    Let rc = mixerGetControlDetails(DeviceID, pmxcd, MIXER_GETCONTROLDETAILSF_LISTTEXT)
    If rc <> 0 Then GoTo Exception 'Error Trap
   
    For Index = LBound(mcdlt) To UBound(mcdlt)
        pmxl.dwLineID = mcdlt(Index).dwParam1
        Let rc = mixerGetLineInfo(DeviceID, pmxl, MIXER_GETLINEINFOF_LINEID)
        If rc <> 0 Then GoTo Exception 'Error Trap
        If pmxl.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE Then
            Exit For
        End If
    Next
    If Index > UBound(mcdlt) Then GoTo Exception
    'Get Control Values
    ReDim mcdb(pmxc.cMultipleItems - 1)
    Let pmxcd.cbDetails = Len(mcdb(0))
    Let pmxcd.paDetails = VarPtr(mcdb(0))
    Let mcdb(Index) = 1
    Let rc = mixerSetControlDetails(DeviceID, pmxcd, MIXER_SETCONTROLDETAILSF_VALUE)
    If rc <> 0 Then GoTo Exception 'Error Trap
Let SelectMicrophone = True
Exit Function
Exception:
End Function
0
 
LVL 1

Author Comment

by:frankmorrison
ID: 13765060
Rubyn,  your code works excellent!!!.
I am about to give you the 500 points;  but, Is there anyway you can also give the code for button1 and 3?
0
 
LVL 5

Expert Comment

by:Rubyn
ID: 13766146
frankmorrison, Yes I can give, but there is a rule in expert-exchange that i cant do homework, I can only give solutions in the place you can't do it by yourself. If you want I can explain the concept behind the code I presented. I can suggest you onething, you try it to do by yourself by the existing code. If you got struck then you open a new thread and ask the doubt, many experts are there to solve and give you knowledge. You can also send a notice to me, so I'll try to guide you. :)
0
 
LVL 1

Author Comment

by:frankmorrison
ID: 13828297
Rubyn,

I looked everywhere on expert-exchange for that rule that you mention.  Could you please send me a link as to where this is posted?.  Additionally, I would not ask you if I could do it myself.
0
 
LVL 5

Expert Comment

by:Rubyn
ID: 13950580
0
 
LVL 1

Author Comment

by:frankmorrison
ID: 13962122
Rubyn,

I am not a student. So, this is NOT homework.  Anyways, Here's your 500 points.
0
 
LVL 4

Expert Comment

by:Ambusy
ID: 21592662
The solution for Visual Basic .NET would be:

create a module, and call the Sub with parameter 0.



Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices
Module Module1
    ' version for Visual Basic DotNet by Martin Martien van der Burgt
    Private Const MAXPNAMELEN As Short = 32 '  max product name length (including NULL)

    'Private Const MIXER_GETCONTROLDETAILSF_LISTTEXT As Integer = &H1
    'Private Const MIXER_GETCONTROLDETAILSF_QUERYMASK As Integer = &HF
    Private Const MIXER_GETCONTROLDETAILSF_VALUE As Integer = &H0

    Private Const MIXER_GETLINECONTROLSF_ALL As Integer = &H0
    'Private Const MIXER_GETLINECONTROLSF_ONEBYID As Integer = &H1
    'Private Const MIXER_GETLINECONTROLSF_ONEBYTYPE As Integer = &H2
    'Private Const MIXER_GETLINECONTROLSF_QUERYMASK As Integer = &HF

    Private Const MIXER_GETLINEINFOF_COMPONENTTYPE As Integer = &H3
    'Private Const MIXER_GETLINEINFOF_DESTINATION As Integer = &H0
    'Private Const MIXER_GETLINEINFOF_LINEID As Integer = &H2
    'Private Const MIXER_GETLINEINFOF_QUERYMASK As Integer = &HF
    Private Const MIXER_GETLINEINFOF_SOURCE As Integer = &H1
    'Private Const MIXER_GETLINEINFOF_TARGETTYPE As Integer = &H4

    Private Const MIXER_LONG_NAME_CHARS As Short = 64
    Private Const MIXER_SHORT_NAME_CHARS As Short = 16

    'Private Const MIXER_OBJECTF_AUX As Integer = &H50000000
    'Private Const MIXER_OBJECTF_HANDLE As Integer = &H80000000
    'Private Const MIXER_OBJECTF_MIDIIN As Integer = &H40000000
    'Private Const MIXER_OBJECTF_MIDIOUT As Integer = &H30000000
    'Private Const MIXER_OBJECTF_MIXER As Integer = &H0
    Private Const MIXER_OBJECTF_WAVEIN As Integer = &H20000000
    'Private Const MIXER_OBJECTF_WAVEOUT As Integer = &H10000000
    'Private Const MIXER_OBJECTF_HMIDIIN As Integer = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIIN)
    'Private Const MIXER_OBJECTF_HMIDIOUT As Integer = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)
    'Private Const MIXER_OBJECTF_HMIXER As Integer = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)
    'Private Const MIXER_OBJECTF_HWAVEIN As Integer = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)
    'Private Const MIXER_OBJECTF_HWAVEOUT As Integer = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)

    'Private Const MIXER_SETCONTROLDETAILSF_CUSTOM As Integer = &H1
    'Private Const MIXER_SETCONTROLDETAILSF_QUERYMASK As Integer = &HF
    'Private Const MIXER_SETCONTROLDETAILSF_VALUE As Integer = &H0

    'Private Const MIXERCONTROL_CONTROLF_DISABLED As Integer = &H80000000
    'Private Const MIXERCONTROL_CONTROLF_MULTIPLE As Integer = &H2
    'Private Const MIXERCONTROL_CONTROLF_UNIFORM As Integer = &H1

    'Private Const MIXERCONTROL_CT_CLASS_CUSTOM As Integer = &H0
    Private Const MIXERCONTROL_CT_CLASS_FADER As Integer = &H50000000
    Private Const MIXERCONTROL_CT_CLASS_LIST As Integer = &H70000000
    'Private Const MIXERCONTROL_CT_CLASS_MASK As Integer = &HF0000000
    'Private Const MIXERCONTROL_CT_CLASS_METER As Integer = &H10000000
    'Private Const MIXERCONTROL_CT_CLASS_NUMBER As Integer = &H30000000
    'Private Const MIXERCONTROL_CT_CLASS_SLIDER As Integer = &H40000000
    Private Const MIXERCONTROL_CT_CLASS_SWITCH As Integer = &H20000000
    'Private Const MIXERCONTROL_CT_CLASS_TIME As Integer = &H60000000
    'Private Const MIXERCONTROL_CT_SC_LIST_MULTIPLE As Integer = &H1000000
    'Private Const MIXERCONTROL_CT_SC_LIST_SINGLE As Integer = &H0
    'Private Const MIXERCONTROL_CT_SC_METER_POLLED As Integer = &H0
    Private Const MIXERCONTROL_CT_SC_SWITCH_BOOLEAN As Integer = &H0
    'Private Const MIXERCONTROL_CT_SC_SWITCH_BUTTON As Integer = &H1000000
    'Private Const MIXERCONTROL_CT_SC_TIME_MICROSECS As Integer = &H0
    'Private Const MIXERCONTROL_CT_SC_TIME_MILLISECS As Integer = &H1000000
    'Private Const MIXERCONTROL_CT_SUBCLASS_MASK As Integer = &HF000000
    Private Const MIXERCONTROL_CT_UNITS_BOOLEAN As Integer = &H10000
    'Private Const MIXERCONTROL_CT_UNITS_CUSTOM As Integer = &H0
    'Private Const MIXERCONTROL_CT_UNITS_DECIBELS As Integer = &H40000 '  in 10ths
    'Private Const MIXERCONTROL_CT_UNITS_MASK As Integer = &HFF0000
    'Private Const MIXERCONTROL_CT_UNITS_PERCENT As Integer = &H50000 '  in 10ths
    'Private Const MIXERCONTROL_CT_UNITS_SIGNED As Integer = &H20000
    'Private Const MIXERCONTROL_CT_UNITS_UNSIGNED As Integer = &H30000
    'Private Const MIXERCONTROL_CONTROLTYPE_FADER As Integer = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
    'Private Const MIXERCONTROL_CONTROLTYPE_SLIDER As Integer = (MIXERCONTROL_CT_CLASS_SLIDER Or MIXERCONTROL_CT_UNITS_SIGNED)
    'Private Const MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER As Integer = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_UNSIGNED)
    'Private Const MIXERCONTROL_CONTROLTYPE_SIGNEDMETER As Integer = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_SIGNED)
    'Private Const MIXERCONTROL_CONTROLTYPE_SINGLESELECT As Integer = (MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_SC_LIST_SINGLE Or MIXERCONTROL_CT_UNITS_BOOLEAN)
    'Private Const MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT As Integer = (MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_SC_LIST_MULTIPLE Or MIXERCONTROL_CT_UNITS_BOOLEAN)
    'Private Const MIXERCONTROL_CONTROLTYPE_BASS As Integer = ((MIXERCONTROL_CONTROLTYPE_FADER) + 2)
    Private Const MIXERCONTROL_CONTROLTYPE_BOOLEAN As Integer = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_SC_SWITCH_BOOLEAN Or MIXERCONTROL_CT_UNITS_BOOLEAN)
    'Private Const MIXERCONTROL_CONTROLTYPE_BOOLEANMETER As Integer = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_BOOLEAN)
    'Private Const MIXERCONTROL_CONTROLTYPE_BUTTON As Integer = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_SC_SWITCH_BUTTON Or MIXERCONTROL_CT_UNITS_BOOLEAN)
    'Private Const MIXERCONTROL_CONTROLTYPE_CUSTOM As Integer = (MIXERCONTROL_CT_CLASS_CUSTOM Or MIXERCONTROL_CT_UNITS_CUSTOM)
    'Private Const MIXERCONTROL_CONTROLTYPE_DECIBELS As Integer = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_DECIBELS)
    'Private Const MIXERCONTROL_CONTROLTYPE_EQUALIZER As Integer = ((MIXERCONTROL_CONTROLTYPE_FADER) + 4)
    'Private Const MIXERCONTROL_CONTROLTYPE_LOUDNESS As Integer = ((MIXERCONTROL_CONTROLTYPE_BOOLEAN) + 4)
    'Private Const MIXERCONTROL_CONTROLTYPE_MICROTIME As Integer = (MIXERCONTROL_CT_CLASS_TIME Or MIXERCONTROL_CT_SC_TIME_MICROSECS Or MIXERCONTROL_CT_UNITS_UNSIGNED)
    'Private Const MIXERCONTROL_CONTROLTYPE_MILLITIME As Integer = (MIXERCONTROL_CT_CLASS_TIME Or MIXERCONTROL_CT_SC_TIME_MILLISECS Or MIXERCONTROL_CT_UNITS_UNSIGNED)
    'Private Const MIXERCONTROL_CONTROLTYPE_MIXER As Integer = ((MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT) + 1)
    'Private Const MIXERCONTROL_CONTROLTYPE_MONO As Integer = ((MIXERCONTROL_CONTROLTYPE_BOOLEAN) + 3)
    'Private Const MIXERCONTROL_CONTROLTYPE_MUTE As Integer = ((MIXERCONTROL_CONTROLTYPE_BOOLEAN) + 2)
    'Private Const MIXERCONTROL_CONTROLTYPE_MUX As Integer = ((MIXERCONTROL_CONTROLTYPE_SINGLESELECT) + 1)
    'Private Const MIXERCONTROL_CONTROLTYPE_ONOFF As Integer = ((MIXERCONTROL_CONTROLTYPE_BOOLEAN) + 1)
    'Private Const MIXERCONTROL_CONTROLTYPE_PAN As Integer = ((MIXERCONTROL_CONTROLTYPE_SLIDER) + 1)
    'Private Const MIXERCONTROL_CONTROLTYPE_PEAKMETER As Integer = ((MIXERCONTROL_CONTROLTYPE_SIGNEDMETER) + 1)
    'Private Const MIXERCONTROL_CONTROLTYPE_PERCENT As Integer = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_PERCENT)
    'Private Const MIXERCONTROL_CONTROLTYPE_QSOUNDPAN As Integer = ((MIXERCONTROL_CONTROLTYPE_SLIDER) + 2)
    'Private Const MIXERCONTROL_CONTROLTYPE_SIGNED As Integer = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_SIGNED)
    'Private Const MIXERCONTROL_CONTROLTYPE_STEREOENH As Integer = ((MIXERCONTROL_CONTROLTYPE_BOOLEAN) + 5)
    'Private Const MIXERCONTROL_CONTROLTYPE_TREBLE As Integer = ((MIXERCONTROL_CONTROLTYPE_FADER) + 3)
    'Private Const MIXERCONTROL_CONTROLTYPE_UNSIGNED As Integer = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
    'Private Const MIXERCONTROL_CONTROLTYPE_VOLUME As Integer = ((MIXERCONTROL_CONTROLTYPE_FADER) + 1)

    Private Const MIXERLINE_COMPONENTTYPE_SRC_FIRST As Integer = &H1000
    Private Const MIXERLINE_COMPONENTTYPE_DST_FIRST As Integer = &H0
    'Private Const MIXERLINE_COMPONENTTYPE_DST_DIGITAL As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 1)
    'Private Const MIXERLINE_COMPONENTTYPE_DST_HEADPHONES As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 5)
    'Private Const MIXERLINE_COMPONENTTYPE_DST_LAST As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 8)
    'Private Const MIXERLINE_COMPONENTTYPE_DST_LINE As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 2)
    'Private Const MIXERLINE_COMPONENTTYPE_DST_MONITOR As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 3)
    'Private Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
    'Private Const MIXERLINE_COMPONENTTYPE_DST_TELEPHONE As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 6)
    'Private Const MIXERLINE_COMPONENTTYPE_DST_UNDEFINED As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 0)
    'Private Const MIXERLINE_COMPONENTTYPE_DST_VOICEIN As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 8)
    Private Const MIXERLINE_COMPONENTTYPE_DST_WAVEIN As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 7)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_ANALOG As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 10)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 9)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 5)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_DIGITAL As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 1)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_LAST As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 10)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_LINE As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2)
    Private Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 7)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 4)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 6)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 0)
    'Private Const MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT As Integer = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 8)
    'Private Const MIXERLINE_LINEF_ACTIVE As Integer = &H1
    'Private Const MIXERLINE_LINEF_DISCONNECTED As Integer = &H8000
    'Private Const MIXERLINE_LINEF_SOURCE As Integer = &H80000000
    'Private Const MIXERLINE_TARGETTYPE_AUX As Short = 5
    'Private Const MIXERLINE_TARGETTYPE_MIDIIN As Short = 4
    'Private Const MIXERLINE_TARGETTYPE_MIDIOUT As Short = 3
    'Private Const MIXERLINE_TARGETTYPE_UNDEFINED As Short = 0
    'Private Const MIXERLINE_TARGETTYPE_WAVEIN As Short = 2
    'Private Const MIXERLINE_TARGETTYPE_WAVEOUT As Short = 1
    'Private Const MIXERR_BASE As Short = 1024
    'Private Const MIXERR_INVALCONTROL As Integer = (MIXERR_BASE + 1)
    'Private Const MIXERR_INVALLINE As Integer = (MIXERR_BASE + 0)
    'Private Const MIXERR_INVALVALUE As Integer = (MIXERR_BASE + 2)
    'Private Const MIXERR_LASTERROR As Integer = (MIXERR_BASE + 2)

    Private Const maxMIXERCONTROLS As Integer = 32
    Private Structure MIXERCONTROLS
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=maxMIXERCONTROLS)> _
        Dim omc() As MIXERCONTROL ' one mixer control
    End Structure
    Private Structure MIXERCONTROL
        Dim cbStruct As Integer '  size in Byte of MIXERCONTROL
        Dim dwControlID As Integer '  unique control id for mixer device
        Dim dwControlType As Integer '  MIXERCONTROL_CONTROLTYPE_xxx
        Dim fdwControl As Integer '  MIXERCONTROL_CONTROLF_xxx
        Dim cMultipleItems As Integer '  if MIXERCONTROL_CONTROLF_MULTIPLE set
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> _
        Dim szShortName As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> _
        Dim szName As String
        Dim Bounds0 As Integer : Dim Bounds1 As Integer : Dim Bounds2 As Integer : Dim Bounds3 As Integer : Dim Bounds4 As Integer : Dim Bounds5 As Integer
        Dim Metrics0 As Integer : Dim Metrics1 As Integer : Dim Metrics2 As Integer : Dim Metrics3 As Integer : Dim Metrics4 As Integer : Dim Metrics5 As Integer
    End Structure
    Private Structure MIXERCONTROLDETAILS
        Dim cbStruct As Integer '  size in Byte of MIXERCONTROLDETAILS
        Dim dwControlID As Integer '  control id to get/set details on
        Dim cChannels As Integer '  number of channels in paDetails array
        Dim item As Integer ' hwndOwner or cMultipleItems
        Dim cbDetails As Integer '  size of _one_ details_XX struct
        Dim paDetails As IntPtr '  pointer to array of details_XX structs
    End Structure
    Private Structure Target ' for use in MIXERLINE and others (embedded structure)
        Dim dwType As Integer '  MIXERLINE_TARGETTYPE_xxxx
        Dim dwDeviceID As Integer '  target device ID of device type
        Dim wMid As Short '  of target device
        Dim wPid As Short '       "
        Dim vDriverVersion As Integer '       "
        <VBFixedString(MAXPNAMELEN), MarshalAs(UnmanagedType.ByValArray, SizeConst:=MAXPNAMELEN)> _
        Public szPname() As Char
    End Structure
    Private Structure MIXERLINE
        Dim cbStruct As Integer '  size of MIXERLINE structure
        Dim dwDestination As Integer '  zero based destination index
        Dim dwSource As Integer '  zero based source index (if source)
        Dim dwLineID As Integer '  unique line id for mixer device
        Dim fdwLine As Integer '  state/information about line
        Dim dwUser As Integer '  driver specific information
        Dim dwComponentType As Integer '  component type line connects to
        Dim cChannels As Integer '  number of channels line supports
        Dim cConnections As Integer '  number of connections (possible)
        Dim cControls As Integer '  number of controls at this line
        <VBFixedString(MIXER_SHORT_NAME_CHARS), MarshalAs(UnmanagedType.ByValArray, SizeConst:=MIXER_SHORT_NAME_CHARS)> _
        Public szShortName() As Char
        <VBFixedString(MIXER_LONG_NAME_CHARS), MarshalAs(UnmanagedType.ByValArray, SizeConst:=MIXER_LONG_NAME_CHARS)> _
        Public szName() As Char
        Dim tTarget As Target
    End Structure
    Private Structure MIXERLINECONTROLS
        Dim cbStruct As Integer '  size in Byte of MIXERLINECONTROLS
        Dim dwLineID As Integer '  line id (from MIXERLINE.dwLineID)
        '   union:                  MIXER_GETLINECONTROLSF_ONEBYID or
        Dim dwControl As Integer '  MIXER_GETLINECONTROLSF_ONEBYTYPE
        Dim cControls As Integer '  count of controls pmxctrl points to
        Dim cbmxctrl As Integer '  size in Byte of _one_ MIXERCONTROL
        Dim pamxctrl As IntPtr '  pointer to first MIXERCONTROL array
    End Structure
    Private Const maxPDATA As Integer = 64
    Private Structure PDATAS
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=maxPDATA)> _
        Dim pData() As Integer
    End Structure

    Private Declare Function mixerGetControlDetails Lib "winmm.dll" Alias "mixerGetControlDetailsA" (ByVal hmxobj As Integer, ByRef pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer
    Private Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (ByVal hmxobj As Integer, ByRef pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Integer) As Integer
    Private Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Integer, ByRef pmxl As MIXERLINE, ByVal fdwInfo As Integer) As Integer
    Private Declare Function mixerSetControlDetails Lib "winmm.dll" (ByVal hmxobj As Integer, ByRef pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer


    Public Function SetMicrophoneOK(ByRef DeviceID As Integer, Optional ByRef sError As String = "") As Boolean
        ' DeviceID usually = 0
        'Dim pmxcaps As MIXERCAPS
        Dim pmxl As MIXERLINE = Nothing
        Dim pmxlc As MIXERLINECONTROLS
        Dim pmxc As MIXERCONTROLS
        Dim pmxcd As MIXERCONTROLDETAILS
        Dim pdt As PDATAS
        Dim rc, Index As Integer
        Dim Text(63) As Byte
        Dim MicIndex As Integer
        'Get WaveIn Destination Number
        pmxl.cbStruct = Marshal.SizeOf(pmxl)
        pmxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN
        rc = mixerGetLineInfo(DeviceID, pmxl, MIXER_OBJECTF_WAVEIN Or MIXER_GETLINEINFOF_COMPONENTTYPE)
        If rc <> 0 Then GoTo Exception 'Error Trap
        'Check For Microphone Source in that destination
        For Index = 0 To pmxl.cConnections - 1
            pmxl.dwSource = Index
            rc = mixerGetLineInfo(DeviceID, pmxl, MIXER_GETLINEINFOF_SOURCE)
            If rc <> 0 Then GoTo Exception 'Error Trap
            If pmxl.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE Then MicIndex = Index : Exit For
        Next
        'Adjust Recording Level of that Microphone
        'ReDim pmxc.omc(pmxl.cControls - 1) would be better, but Marshaling allows only Fixed Length Arrays in structures. Hope 32 is enough
        ReDim pmxc.omc(maxMIXERCONTROLS - 1)
        pmxlc.cbStruct = Marshal.SizeOf(pmxlc)
        pmxlc.dwLineID = pmxl.dwLineID
        pmxlc.cControls = pmxl.cControls
        pmxlc.cbmxctrl = Marshal.SizeOf(pmxc.omc(0))
        pmxlc.pamxctrl = Marshal.AllocCoTaskMem(Marshal.SizeOf(pmxc.omc(0)) * maxMIXERCONTROLS)
        rc = mixerGetLineControls(DeviceID, pmxlc, MIXER_OBJECTF_WAVEIN Or MIXER_GETLINECONTROLSF_ALL)
        If rc <> 0 Then GoTo Exception 'Error Trap
        pmxc = CType(Marshal.PtrToStructure(pmxlc.pamxctrl, GetType(MIXERCONTROLS)), MIXERCONTROLS)
        Marshal.FreeCoTaskMem(pmxlc.pamxctrl)
        ReDim pdt.pData(maxPDATA)
        For Index = LBound(pmxc.omc) To LBound(pmxc.omc) + pmxl.cControls - 1
            If pmxc.omc(Index).dwControlType = (pmxc.omc(Index).dwControlType Or MIXERCONTROL_CT_CLASS_FADER) Then
                'set its fader control to 75% of maximum
                pmxcd.cbStruct = Marshal.SizeOf(pmxcd)
                pmxcd.cChannels = 1
                pmxcd.dwControlID = pmxc.omc(Index).dwControlID
                pmxcd.cbDetails = Marshal.SizeOf(pdt.pData(0))
                pmxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(pdt.pData(0)) * maxPDATA)
                pdt.pData(0) = pmxc.omc(Index).Bounds1 * 0.75 ' zet volume op 75%
                Marshal.StructureToPtr(pdt, pmxcd.paDetails, False)
                rc = mixerSetControlDetails(DeviceID, pmxcd, MIXER_GETCONTROLDETAILSF_VALUE)
                Marshal.FreeCoTaskMem(pmxcd.paDetails)
                If rc <> 0 Then GoTo Exception 'Error Trap
            ElseIf pmxc.omc(Index).dwControlType = (pmxc.omc(Index).dwControlType Or MIXERCONTROL_CONTROLTYPE_BOOLEAN) Then
                'Set Boost/ACG/Incr/... to ON
                pmxcd.cbStruct = Marshal.SizeOf(pmxcd)
                pmxcd.cChannels = 1
                pmxcd.dwControlID = pmxc.omc(Index).dwControlID
                pmxcd.cbDetails = Marshal.SizeOf(pdt.pData(0))
                pmxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(pdt.pData(0)) * maxPDATA)
                pdt.pData(0) = 1 'On
                Marshal.StructureToPtr(pdt, pmxcd.paDetails, False)
                rc = mixerSetControlDetails(DeviceID, pmxcd, MIXER_GETCONTROLDETAILSF_VALUE)
                Marshal.FreeCoTaskMem(pmxcd.paDetails)
                If rc <> 0 Then GoTo Exception 'Error Trap
            End If
        Next

        pmxl.cbStruct = Marshal.SizeOf(pmxl)
        pmxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN
        rc = mixerGetLineInfo(DeviceID, pmxl, MIXER_OBJECTF_WAVEIN Or MIXER_GETLINEINFOF_COMPONENTTYPE)

        'ReDim pmxc.omc(pmxl.cControls - 1)
        ReDim pmxc.omc(maxMIXERCONTROLS - 1)
        pmxlc.cbStruct = Marshal.SizeOf(pmxlc)
        pmxlc.dwLineID = pmxl.dwLineID
        pmxlc.cControls = pmxl.cControls
        pmxlc.cbmxctrl = Marshal.SizeOf(pmxc.omc(0))
        pmxlc.pamxctrl = Marshal.AllocCoTaskMem(Marshal.SizeOf(pmxc.omc(0)) * maxMIXERCONTROLS)
        rc = mixerGetLineControls(DeviceID, pmxlc, MIXER_OBJECTF_WAVEIN Or MIXER_GETLINECONTROLSF_ALL)
        If rc <> 0 Then GoTo Exception 'Error Trap
        pmxc = CType(Marshal.PtrToStructure(pmxlc.pamxctrl, GetType(MIXERCONTROLS)), MIXERCONTROLS)
        Marshal.FreeCoTaskMem(pmxlc.pamxctrl)
        For Index = LBound(pmxc.omc) To LBound(pmxc.omc) + pmxl.cControls - 1
            'set the microphone in multiple select to "selected"
            If pmxc.omc(Index).dwControlType = (pmxc.omc(Index).dwControlType Or MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_UNITS_BOOLEAN) Then
                'ReDim pdata(pmxc.omc(Index).cMultipleItems - 1)
                ReDim pdt.pData(maxPDATA) ' Marshal allows Fixed length arrays in structures only
                pmxcd.dwControlID = pmxc.omc(Index).dwControlID
                pmxcd.item = pmxc.omc(Index).cMultipleItems
                pmxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(pdt.pData(0)) * maxPDATA)
                pdt.pData(pmxcd.item - MicIndex - 1) = 1 ' select microphone
                Marshal.StructureToPtr(pdt, pmxcd.paDetails, False)
                rc = mixerSetControlDetails(DeviceID, pmxcd, MIXER_GETCONTROLDETAILSF_VALUE)
                Marshal.FreeCoTaskMem(pmxcd.paDetails)
                If rc <> 0 Then GoTo Exception 'Error Trap
            End If
        Next
        SetMicrophoneOK = True
        Exit Function
Exception:
        SetMicrophoneOK = False
    End Function
End Modul
0
 

Expert Comment

by:DavidQu
ID: 22322108
If Rubyn is still around to provide an explanation about how this code works, that would be great.  I'm not a VB programmer but the code is readable anyway.  The issue is more at the level of the system calls.  It turns out that I'm attempting to perform this same function but the results are limited.  For example, I'm having trouble selecting a USB microphone as it does not have a 'select' component associated with its line.  Excuse me if I'm missing something obvious.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question