• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1602
  • Last Modified:

control the mic , line In volume

i have a program that looks like NetMeeting but it has a very small problem is that when the connection between two computers is established, the mic recording volume is set to a too small value so that when someone wants to talk the other can't hear him, or he is obliged to increase the mic recording volume level manually,

I want a simple code that increases the mic recording volume in vb.net

Thanks
0
pcnet2004
Asked:
pcnet2004
  • 8
  • 5
  • 2
1 Solution
 
ajaikumarrCommented:
0
 
pcnet2004Author Commented:
this does not work because:
first it is not on vb.net 2003
second it does not meet my request

i have this code

Attribute VB_Name = "Module1"

'Call the OpenMixer function (ususally mixer 0).
'Then you can get/set all the primary mixer controls with the SetVolume, GetVolume, SetMute & GetMute functions.
Option Explicit

' ***************************************************************************
'                        Mixer API Support (winmm.dll)
' ***************************************************************************
Private Const MMSYSERR_NOERROR = 0
Private Const MIXER_SHORT_NAME_CHARS = 16
Private Const MIXER_LONG_NAME_CHARS = 64
Private Const MAXPNAMELEN = 32                  ' max product name length (including NULL)
Private Const MAXERRORLENGTH = 128              ' max error text length (including final NULL)
Private Const MM_MIXM_LINE_CHANGE = &H3D0       ' mixer line change notify
Private Const MM_MIXM_CONTROL_CHANGE = &H3D1    ' mixer control change notify
'
'   MMRESULT error return values specific to the mixer API
'
Private Const MIXERR_BASE = 1024
Private Const MIXERR_INVALLINE = (MIXERR_BASE + 0)
Private Const MIXERR_INVALCONTROL = (MIXERR_BASE + 1)
Private Const MIXERR_INVALVALUE = (MIXERR_BASE + 2)
Private Const MIXERR_LASTERROR = (MIXERR_BASE + 2)

Private Const MIXER_OBJECTF_HANDLE = &H80000000
Private Const MIXER_OBJECTF_MIXER = &H0&
Private Const MIXER_OBJECTF_HMIXER = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)
Private Const MIXER_OBJECTF_WAVEOUT = &H10000000
Private Const MIXER_OBJECTF_HWAVEOUT = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)
Private Const MIXER_OBJECTF_WAVEIN = &H20000000
Private Const MIXER_OBJECTF_HWAVEIN = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)
Private Const MIXER_OBJECTF_MIDIOUT = &H30000000
Private Const MIXER_OBJECTF_HMIDIOUT = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)
Private Const MIXER_OBJECTF_MIDIIN = &H40000000
Private Const MIXER_OBJECTF_HMIDIIN = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIIN)
Private Const MIXER_OBJECTF_AUX = &H50000000
'
'   MIXERLINE.fdwLine
'
Private Const MIXERLINE_LINEF_ACTIVE = &H1&
Private Const MIXERLINE_LINEF_DISCONNECTED = &H8000&
Private Const MIXERLINE_LINEF_SOURCE = &H80000000
'
'   MIXERLINE.dwComponentType
'
Private Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
Private Const MIXERLINE_COMPONENTTYPE_DST_UNDEFINED = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 0)
Private Const MIXERLINE_COMPONENTTYPE_DST_DIGITAL = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 1)
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_HEADPHONES = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 5)
Private Const MIXERLINE_COMPONENTTYPE_DST_TELEPHONE = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 6)
Private Const MIXERLINE_COMPONENTTYPE_DST_WAVEIN = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 7)
Private Const MIXERLINE_COMPONENTTYPE_DST_VOICEIN = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 8)
Private Const MIXERLINE_COMPONENTTYPE_DST_LAST = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 8)

Private Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&
Private Const MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 0)
Private Const MIXERLINE_COMPONENTTYPE_SRC_DIGITAL = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 1)
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_SYNTHESIZER = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 4)
Private Const MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 5)
Private Const MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 6)
Private Const MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 7)
Private Const MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 8)
Private Const MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 9)
Private Const MIXERLINE_COMPONENTTYPE_SRC_ANALOG = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 10)
Private Const MIXERLINE_COMPONENTTYPE_SRC_LAST = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 10)
'
'   MIXERLINE.Target.dwType
'
Private Const MIXERLINE_TARGETTYPE_UNDEFINED = 0
Private Const MIXERLINE_TARGETTYPE_WAVEOUT = 1
Private Const MIXERLINE_TARGETTYPE_WAVEIN = 2
Private Const MIXERLINE_TARGETTYPE_MIDIOUT = 3
Private Const MIXERLINE_TARGETTYPE_MIDIIN = 4
Private Const MIXERLINE_TARGETTYPE_AUX = 5

Private Const MIXER_GETLINEINFOF_DESTINATION = &H0&
Private Const MIXER_GETLINEINFOF_SOURCE = &H1&
Private Const MIXER_GETLINEINFOF_LINEID = &H2&
Private Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
Private Const MIXER_GETLINEINFOF_TARGETTYPE = &H4&
Private Const MIXER_GETLINEINFOF_QUERYMASK = &HF&
'
'   MIXERCONTROL.fdwControl
'
Private Const MIXERCONTROL_CONTROLF_UNIFORM = &H1&
Private Const MIXERCONTROL_CONTROLF_MULTIPLE = &H2&
Private Const MIXERCONTROL_CONTROLF_DISABLED = &H80000000
'
'   MIXERCONTROL_CONTROLTYPE_xxx building block defines
'
Private Const MIXERCONTROL_CT_CLASS_MASK = &HF0000000
Private Const MIXERCONTROL_CT_CLASS_CUSTOM = &H0&
Private Const MIXERCONTROL_CT_CLASS_METER = &H10000000
Private Const MIXERCONTROL_CT_CLASS_SWITCH = &H20000000
Private Const MIXERCONTROL_CT_CLASS_NUMBER = &H30000000
Private Const MIXERCONTROL_CT_CLASS_SLIDER = &H40000000
Private Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
Private Const MIXERCONTROL_CT_CLASS_TIME = &H60000000
Private Const MIXERCONTROL_CT_CLASS_LIST = &H70000000
Private Const MIXERCONTROL_CT_SUBCLASS_MASK = &HF000000
Private Const MIXERCONTROL_CT_SC_SWITCH_BOOLEAN = &H0&
Private Const MIXERCONTROL_CT_SC_SWITCH_BUTTON = &H1000000
Private Const MIXERCONTROL_CT_SC_METER_POLLED = &H0&
Private Const MIXERCONTROL_CT_SC_TIME_MICROSECS = &H0&
Private Const MIXERCONTROL_CT_SC_TIME_MILLISECS = &H1000000
Private Const MIXERCONTROL_CT_SC_LIST_SINGLE = &H0&
Private Const MIXERCONTROL_CT_SC_LIST_MULTIPLE = &H1000000
Private Const MIXERCONTROL_CT_UNITS_MASK = &HFF0000
Private Const MIXERCONTROL_CT_UNITS_CUSTOM = &H0&
Private Const MIXERCONTROL_CT_UNITS_BOOLEAN = &H10000
Private Const MIXERCONTROL_CT_UNITS_SIGNED = &H20000
Private Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000
Private Const MIXERCONTROL_CT_UNITS_DECIBELS = &H40000  '  in 10ths
Private Const MIXERCONTROL_CT_UNITS_PERCENT = &H50000   '  in 10ths
'
'   Commonly used control types for specifying MIXERCONTROL.dwControlType
'
Private Const MIXERCONTROL_CONTROLTYPE_CUSTOM = (MIXERCONTROL_CT_CLASS_CUSTOM Or MIXERCONTROL_CT_UNITS_CUSTOM)
Private Const MIXERCONTROL_CONTROLTYPE_BOOLEANMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_SIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_SIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_PEAKMETER = (MIXERCONTROL_CONTROLTYPE_SIGNEDMETER + 1)
Private Const MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_BOOLEAN = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_SC_SWITCH_BOOLEAN Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_ONOFF = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 1)
Private Const MIXERCONTROL_CONTROLTYPE_MUTE = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 2)
Private Const MIXERCONTROL_CONTROLTYPE_MONO = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 3)
Private Const MIXERCONTROL_CONTROLTYPE_LOUDNESS = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 4)
Private Const MIXERCONTROL_CONTROLTYPE_STEREOENH = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 5)
Private Const MIXERCONTROL_CONTROLTYPE_BUTTON = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_SC_SWITCH_BUTTON Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_DECIBELS = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_DECIBELS)
Private Const MIXERCONTROL_CONTROLTYPE_SIGNED = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_SIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_UNSIGNED = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_PERCENT = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_PERCENT)
Private Const MIXERCONTROL_CONTROLTYPE_SLIDER = (MIXERCONTROL_CT_CLASS_SLIDER Or MIXERCONTROL_CT_UNITS_SIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_PAN = (MIXERCONTROL_CONTROLTYPE_SLIDER + 1)
Private Const MIXERCONTROL_CONTROLTYPE_QSOUNDPAN = (MIXERCONTROL_CONTROLTYPE_SLIDER + 2)
Private Const MIXERCONTROL_CONTROLTYPE_FADER = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Private Const MIXERCONTROL_CONTROLTYPE_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1)
Private Const MIXERCONTROL_CONTROLTYPE_BASS = (MIXERCONTROL_CONTROLTYPE_FADER + 2)
Private Const MIXERCONTROL_CONTROLTYPE_TREBLE = (MIXERCONTROL_CONTROLTYPE_FADER + 3)
Private Const MIXERCONTROL_CONTROLTYPE_EQUALIZER = (MIXERCONTROL_CONTROLTYPE_FADER + 4)
Private Const MIXERCONTROL_CONTROLTYPE_SINGLESELECT = (MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_SC_LIST_SINGLE Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_MUX = (MIXERCONTROL_CONTROLTYPE_SINGLESELECT + 1)
Private Const MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT = (MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_SC_LIST_MULTIPLE Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Private Const MIXERCONTROL_CONTROLTYPE_MIXER = (MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT + 1)
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 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_GETCONTROLDETAILSF_VALUE = &H0&
Private Const MIXER_GETCONTROLDETAILSF_LISTTEXT = &H1&
Private Const MIXER_GETCONTROLDETAILSF_QUERYMASK = &HF&

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


' mixer API types

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 Target    ' for use in MIXERLINE and others (embedded structure)
    dwType          As Long                 '  MIXERLINE_TARGETPrivate Type_xxxx
    dwDeviceID      As Long                 '  target device ID of device Private 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 Private 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 MIXERCONTROL
    cbStruct        As Long                 '  size in Byte of MIXERCONTROL
    dwControlID     As Long                 '  unique control id for mixer device
    dwControlType   As Long                 '  MIXERCONTROL_CONTROLPrivate Type_xxx
    fdwControl      As Long                 '  MIXERCONTROL_CONTROLF_xxx
    cMultipleItems  As Long                 '  if MIXERCONTROL_CONTROLF_MULTIPLE set
    szShortName(1 To MIXER_SHORT_NAME_CHARS) As Byte
    szName(1 To MIXER_LONG_NAME_CHARS) As Byte
    'Bounds(1 To 6)  As Long                 '  Longest member of the Bounds union
    'Metrics(1 To 6) As Long                 '  Longest member of the Metrics union
    ' alternate defs for two items above
    lMinimum As Long                        '  Minimum value
    lMaximum As Long                        '  Maximum value
    RESERVED(10) As Long                    '  reserved structure space
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_ONEBYPrivate Type
        cControls       As Long             '  count of controls pmxctrl points to
        cbmxctrl        As Long             '  size in Byte of _one_ MIXERCONTROL
        'pamxctrl        As MIXERCONTROL     '  pointer to first MIXERCONTROL array
        pamxctrl        As Long             '  pointer to first MIXERCONTROL array
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 MIXERCONTROLDETAILS_LISTTEXT
        dwParam1 As Long
        dwParam2 As Long
        szName As String * MIXER_LONG_NAME_CHARS
End Type

Private Type MIXERCONTROLDETAILS_BOOLEAN
        fValue As Long
End Type

Private Type MIXERCONTROLDETAILS_SIGNED
        lValue As Long
End Type

Private Type MIXERCONTROLDETAILS_UNSIGNED
        dwValue As Long
End Type

' mixer API prototypes
Private Declare Function mixerGetNumDevs Lib "winmm.dll" () As Long
Private Declare Function mixerGetDevCaps Lib "winmm.dll" Alias "mixerGetDevCapsA" (ByVal uMxId As Long, pmxcaps As MIXERCAPS, ByVal cbmxcaps 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 mixerClose Lib "winmm.dll" (ByVal hmx As Long) 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 mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Long, pmxl As MIXERLINE, ByVal fdwInfo 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 mixerGetControlDetails Lib "winmm.dll" Alias "mixerGetControlDetailsA" (ByVal hmxobj As Long, pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long
Private Declare Function mixerSetControlDetails Lib "winmm.dll" (ByVal hmxobj As Long, pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long

' misc API prototypes
Private Declare Sub CopyStructFromPtr Lib "kernel32" Alias "RtlMoveMemory" (struct As Any, ByVal ptr As Long, ByVal cb As Long)
Private Declare Sub CopyPtrFromStruct Lib "kernel32" Alias "RtlMoveMemory" (ByVal ptr As Long, struct As Any, ByVal cb As Long)
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long

Private Const CALLBACK_WINDOW = &H10000
Private Const GWL_WNDPROC = (-4)
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private uMixerControls(20)      As MIXERCONTROL ' local array to store mixer controls
Private hMixerHandle            As Long         ' handle for mixer

' enums to identify mixer volume controls
Public Enum VOL_CONTROL
    SPEAKER = 0
    LINEIN = 1
    MICROPHONE = 2
    SYNTHESIZER = 3
    COMPACTDISC = 4
    WAVEOUT = 5
    AUXILIARY = 6
End Enum

' enums to identify mixer mute controls
Public Enum MUTE_CONTROL
    SPEAKER_MUTE = 7
    LINEIN_MUTE = 8
    MICROPHONE_MUTE = 9
    SYNTHESIZER_MUTE = 10
    COMPACTDISC_MUTE = 11
    WAVEOUT_MUTE = 12
    AUXILIARY_MUTE = 13
End Enum


Public Function OpenMixer(ByVal MixerNumber As Long) As Long

    Dim ret             As Long
   
    ' is there a mixer available?
    If MixerNumber < 0 Or MixerNumber > mixerGetNumDevs - 1 Then Exit Function
   
    ' open the mixer
    ret = mixerOpen(hMixerHandle, MixerNumber, 0, 0, 0)
    If ret <> MMSYSERR_NOERROR Then Exit Function

    ' get the primary line controls by name, (this does not get all of the controls).
   
    ' speaker (master) volume
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(SPEAKER))
    ' microphone volume
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(MICROPHONE))
    ' Line volume
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY, MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(AUXILIARY))
    ' CD volume
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC, MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(COMPACTDISC))
    ' Synthesizer volume
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER, MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(SYNTHESIZER))
    ' wave volume
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT, MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(WAVEOUT))
    ' Aux volume
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_LINE, MIXERCONTROL_CONTROLTYPE_VOLUME, uMixerControls(LINEIN))
   
    ' speaker (master) mute
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(SPEAKER_MUTE))
    ' microphone mute
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(MICROPHONE_MUTE))
    ' Line mute
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY, MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(AUXILIARY_MUTE))
    ' CD mute
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC, MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(COMPACTDISC_MUTE))
    ' Synthesizer mute
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER, MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(SYNTHESIZER_MUTE))
    ' wave mute
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT, MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(WAVEOUT_MUTE))
    ' Aux mute
    ret = GetMixerControl(hMixerHandle, MIXERLINE_COMPONENTTYPE_SRC_LINE, MIXERCONTROL_CONTROLTYPE_MUTE, uMixerControls(LINEIN_MUTE))

    ' return the mixer handle
    OpenMixer = True

End Function

Public Function CloseMixer() As Long

    CloseMixer = mixerClose(hMixerHandle)
    hMixerHandle = 0
   
End Function


Public Function SetVolume(Control As VOL_CONTROL, ByVal NewVolume As Long) As Long

    SetVolume = SetControlValue(hMixerHandle, uMixerControls(Control), NewVolume)

End Function

Public Function GetVolume(Control As VOL_CONTROL) As Long

    GetVolume = GetControlValue(hMixerHandle, uMixerControls(Control))

End Function

Public Function SetMute(Control As MUTE_CONTROL, ByVal MuteState As Boolean) As Boolean
   
    Dim mute    As Long
    mute = Abs(MuteState)
   
    SetMute = SetControlValue(hMixerHandle, uMixerControls(Control), mute)
   
End Function

Public Function GetMute(Control As MUTE_CONTROL) As Boolean

    GetMute = CBool(-GetControlValue(hMixerHandle, uMixerControls(Control)))

End Function

Private Function GetMixerControl(ByVal hMixer As Long, ByVal componentType As Long, ByVal ctrlType As Long, ByRef mxc As MIXERCONTROL) As Long
                             
    ' This function attempts to obtain a mixer control. Returns True if successful.
    Dim mxlc        As MIXERLINECONTROLS
    Dim mxl         As MIXERLINE
    Dim hMem        As Long
    Dim ret         As Long
             
    mxl.cbStruct = Len(mxl)
    mxl.dwComponentType = componentType
   
    ' Obtain a line corresponding to the component type
    ret = mixerGetLineInfo(hMixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)
         
    If ret = MMSYSERR_NOERROR Then
        mxlc.cbStruct = Len(mxlc)
        mxlc.dwLineID = mxl.dwLineID
        mxlc.dwControl = ctrlType
        mxlc.cControls = 1
        mxlc.cbmxctrl = Len(mxc)
             
        ' Allocate a buffer for the control
        hMem = GlobalAlloc(&H40, Len(mxc))
        mxlc.pamxctrl = GlobalLock(hMem)
        mxc.cbStruct = Len(mxc)
             
        ' Get the control
        ret = mixerGetLineControls(hMixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
                 
        If ret = MMSYSERR_NOERROR Then
            GetMixerControl = True
                 
            ' Copy the control into the destination structure
            CopyStructFromPtr mxc, mxlc.pamxctrl, Len(mxc)
        Else
            GetMixerControl = False
        End If
        GlobalFree (hMem)
        Exit Function
    End If
     
    GetMixerControl = False
   
End Function


Private Function SetControlValue(ByVal hMixer As Long, mxc As MIXERCONTROL, ByVal NewVolume As Long) As Boolean
   
    'This function sets the value for a control. Returns True if successful
                             
    Dim mxcd    As MIXERCONTROLDETAILS
    Dim vol     As MIXERCONTROLDETAILS_UNSIGNED
    Dim hMem    As Long
    Dim ret     As Long

    mxcd.item = 0
    mxcd.dwControlID = mxc.dwControlID
    mxcd.cbStruct = Len(mxcd)
    mxcd.cbDetails = Len(vol)

    ' Allocate a buffer for the control value buffer
    hMem = GlobalAlloc(&H40, Len(vol))
    mxcd.paDetails = GlobalLock(hMem)
    mxcd.cChannels = 1

    ' setup value, use percent of range if max is greater than 100
    If mxc.lMaximum > 100 Then
        vol.dwValue = NewVolume * (mxc.lMaximum \ 100)
    Else
        vol.dwValue = NewVolume
    End If
    If vol.dwValue > mxc.lMaximum Then vol.dwValue = mxc.lMaximum
    If vol.dwValue < mxc.lMinimum Then vol.dwValue = mxc.lMinimum

    ' Copy the data into the control value buffer
    CopyPtrFromStruct mxcd.paDetails, vol, Len(vol)
         
    ' Set the control value
    ret = mixerSetControlDetails(hMixer, mxcd, MIXER_SETCONTROLDETAILSF_VALUE)
    GlobalFree (hMem)

    If ret = MMSYSERR_NOERROR Then SetControlValue = True
   
End Function

Private Function GetControlValue(ByVal hMixer As Long, mxc As MIXERCONTROL) As Long
    'This function gets the value for a control.

    Dim mxcd    As MIXERCONTROLDETAILS
    Dim vol     As MIXERCONTROLDETAILS_UNSIGNED
    Dim hMem    As Long
    Dim ret     As Long

    mxcd.item = 0
    mxcd.dwControlID = mxc.dwControlID
    mxcd.cbStruct = Len(mxcd)
    mxcd.cbDetails = Len(vol)

    hMem = GlobalAlloc(&H40, Len(vol))
    mxcd.paDetails = GlobalLock(hMem)
    mxcd.cChannels = 1

    ' Get the control value
    ret = mixerGetControlDetails(hMixer, mxcd, MIXER_GETCONTROLDETAILSF_VALUE)

    ' Copy the data into the control value buffer
    CopyStructFromPtr vol, mxcd.paDetails, Len(vol)

    If mxc.lMaximum > 100 Then
        GetControlValue = (vol.dwValue * 100) / mxc.lMaximum - mxc.lMinimum
    Else
        GetControlValue = vol.dwValue
    End If

    GlobalFree (hMem)

End Function


it works on vb6 but i don't know well vb6 and i need to translated into vb.net 2003
i know that declaring a variable is done by "dim var as vartype"
 but some syntax i don't know how to translated please help me as fast as you can
0
 
pcnet2004Author Commented:
i can eliminate from this stuff, listen please

what i want exactly is set up or down the microphone recording level volume

can this help

I hope so
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
pcnet2004Author Commented:
if you can't help please tell me i need a quick answer but if you are trying to help me please also tell me what are you thinking to do so i can maybe find a way to solve it
0
 
ajaikumarrCommented:
Hai,

I'm trying to get some code for you... I dont know how to deal with vb.net... But I'm sure that i can guide you... Will let you know it tomorrow (have to check it tonight)...

Bye
Ajai
0
 
ajaikumarrCommented:
Hai,

I'm getting afraid that doing MixerControl (Mic Volume Control) will take a long time about changing the code from vb to vb.net... As we dont have an property or event to interact directly to mic control anyhow we have to use the API's to to set the volume of Mic. So I would sugesst you to create a dll on VB and then interop that dll to vb.net...

Some of the code i tried on vb.net and still getting some error on this.
Imports System.Runtime.InteropServices

Public Class MicVolumeControl
#Region " Variables declartion "
    Private MicVolume As MIXERCONTROL
    Private rc As Long
    Private hmixer As Long
    Private ok As Boolean

    Private Const MMSYSERR_NOERROR = 0
    Private Const MAXPNAMELEN = 32
    Private Const MIXER_LONG_NAME_CHARS = 64
    Private Const MIXER_SHORT_NAME_CHARS = 16
    Private Const MIXER_SETCONTROLDETAILSF_VALUE = &H0&
    Private Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
    Private Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&
    Private Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
    Private Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
    Private Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&
    Private Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
    Private Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3)
    Private Const MIXERLINE_COMPONENTTYPE_SRC_LINE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2)
    Private Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
    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_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1)
    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, ByVal 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, ByVal pumxID As Long, ByVal fdwId As Long) As Long
    Private Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (ByVal hmxobj As Long, ByVal pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Long) As Long
    Private Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Long, ByVal pmxl As MIXERLINE, ByVal fdwInfo As Long) As Long
    'Private Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Integer, ByVal pmxl As MIXERLINE, ByVal fdwInfo As Integer) As Integer
    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" (ByRef phmx As Integer, ByVal uMxId As Integer, ByVal dwCallback As Integer, ByVal dwInstance As Integer, ByVal fdwOpen As Integer) As Integer
    'Private Declare Function mixerOpen Lib "winmm.dll" (ByVal 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, ByVal pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long
    Private Declare Sub CopyStructFromPtr Lib "kernel32" Alias "RtlMoveMemory" (ByVal struct As Object, ByVal ptr As Long, ByVal cb As Long)
    Private Declare Sub CopyPtrFromStruct Lib "kernel32" Alias "RtlMoveMemory" (ByVal ptr As Long, ByVal struct As Object, ByVal cb As Long)
    Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
    Private Declare Function GlobalLock Lib "kernel32" (ByVal hmem As Long) As Long
    Private Declare Function GlobalFree Lib "kernel32" (ByVal hmem As Long) As Long

    Private Structure MIXERCAPS
        Dim wMid As Integer                   '  manufacturer id
        Dim wPid As Integer                   '  product id
        Dim vDriverVersion As Long            '  version of the driver
        Dim szPname As String  '  product name
        Dim fdwSupport As Long                '  misc. support bits
        Dim cDestinations As Long             '  count of destinations
    End Structure

    Private Structure MIXERCONTROL
        Dim cbStruct As Long           '  size in Byte of MIXERCONTROL
        Dim dwControlID As Long        '  unique control id for mixer device
        Dim dwControlStructure As Long      '  MIXERCONTROL_CONTROLTYPE_xxx
        Dim fdwControl As Long          '  MIXERCONTROL_CONTROLF_xxx
        Dim cMultipleItems As Long      '  if MIXERCONTROL_CONTROLF_MULTIPLE set
        Dim szShortName As String            ' short name of control
        Dim szName As String     ' long name of control
        Dim lMinimum As Long           '  Minimum value
        Dim lMaximum As Long           '  Maximum value
        Dim reserved() As Long       '  reserved structure space
    End Structure

    Private Structure MIXERCONTROLDETAILS
        Dim cbStruct As Long       '  size in Byte of MIXERCONTROLDETAILS
        Dim dwControlID As Long    '  control id to get/set details on
        Dim cChannels As Long      '  number of channels in paDetails array
        Dim item As Long           '  hwndOwner or cMultipleItems
        Dim cbDetails As Long      '  size of _one_ details_XX struct
        Dim paDetails As Long      '  pointer to array of details_XX structs
    End Structure

    Private Structure MIXERCONTROLDETAILS_UNSIGNED
        Dim dwValue As Long        '  value of the control
    End Structure

    Private Structure MIXERLINE
        Dim cbStruct As Long               '  size of MIXERLINE structure
        Dim dwDestination As Long          '  zero based destination index
        Dim dwSource As Long               '  zero based source index (if source)
        Dim dwLineID As Long               '  unique line id for mixer device
        Dim fdwLine As Long                '  state/information about line
        Dim dwUser As Long                 '  driver specific information
        Dim dwComponentStructure As Long        '  component Structure line connects to
        Dim cChannels As Long              '  number of channels line supports
        Dim cConnections As Long           '  number of connections (possible)
        Dim cControls As Long              '  number of controls at this line
        Dim szShortName As String
        Dim szName As String
        Dim dwStructure As Long
        Dim dwDeviceID As Long
        Dim wMid As Integer
        Dim wPid As Integer
        Dim vDriverVersion As Long
        Dim szPname As String
        Dim dwComponentType As Long
    End Structure

    Private Structure MIXERLINECONTROLS
        Dim cbStruct As Long       '  size in Byte of MIXERLINECONTROLS
        Dim dwLineID As Long       '  line id (from MIXERLINE.dwLineID)
        '  MIXER_GETLINECONTROLSF_ONEBYID or
        Dim dwControl As Long      '  MIXER_GETLINECONTROLSF_ONEBYTYPE
        Dim cControls As Long      '  count of controls pmxctrl points to
        Dim cbmxctrl As Long       '  size in Byte of _one_ MIXERCONTROL
        Dim pamxctrl As Long       '  pointer to first MIXERCONTROL array
    End Structure
#End Region

#Region " Constructor "
    Sub New()
        rc = mixerOpen(hmixer, 0, 0, 0, 0)

        If ((MMSYSERR_NOERROR <> rc)) Then
            MsgBox("Couldn't open the mixer.")
            Exit Sub
        End If

        ok = GetVolumeControl()
    End Sub
#End Region

    ' This function attempts to obtain a mixer control. Returns True if successful.
    Private Function GetVolumeControl() As Boolean
        Dim mxlc As MIXERLINECONTROLS
        Dim mxl As MIXERLINE
        Dim hmem As Long

        mxl.cbStruct = Marshal.SizeOf(mxl)
        mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE

        ' Obtain a line corresponding to the component type
        rc = mixerGetLineInfo(hmixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)


        If (MMSYSERR_NOERROR = rc) Then
            mxlc.cbStruct = Len(mxlc)
            mxlc.dwLineID = mxl.dwLineID
            mxlc.dwControl = MIXERCONTROL_CONTROLTYPE_VOLUME
            mxlc.cControls = 1
            mxlc.cbmxctrl = Len(MicVolume)

            ' Allocate a buffer for the control
            hmem = GlobalAlloc(&H40, Len(MicVolume))
            mxlc.pamxctrl = GlobalLock(hmem)
            MicVolume.cbStruct = Len(MicVolume)

            ' Get the control
            rc = mixerGetLineControls(hmixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)

            If (MMSYSERR_NOERROR = rc) Then
                GetVolumeControl = True

                ' Copy the control into the destination structure
                CopyStructFromPtr(MicVolume, mxlc.pamxctrl, Len(MicVolume))
            Else
                GetVolumeControl = False
            End If
            GlobalFree(hmem)
            Exit Function
        End If

        GetVolumeControl = False
    End Function

    'This function sets the value for a volume control. Returns True if successful
    Public Function SetVolumeControl(ByVal volume As Long) As Boolean
        Dim mxcd As MIXERCONTROLDETAILS
        Dim vol As MIXERCONTROLDETAILS_UNSIGNED
        Dim hmem As Object

        mxcd.item = 0
        mxcd.dwControlID = MicVolume.dwControlID
        mxcd.cbStruct = Len(mxcd)
        mxcd.cbDetails = Len(vol)

        ' Allocate a buffer for the control value buffer
        hmem = GlobalAlloc(&H40, Len(vol))
        mxcd.paDetails = GlobalLock(hmem)
        mxcd.cChannels = 1
        vol.dwValue = volume

        ' Copy the data into the control value buffer
        CopyPtrFromStruct(mxcd.paDetails, vol, Len(vol))

        ' Set the control value
        rc = mixerSetControlDetails(hmixer, mxcd, MIXER_SETCONTROLDETAILSF_VALUE)

        GlobalFree(hmem)
        If (MMSYSERR_NOERROR = rc) Then
            SetVolumeControl = True
        Else
            SetVolumeControl = False
        End If
    End Function
End Class

Please let me know what do you think about this.

Bye
Ajai
0
 
pcnet2004Author Commented:
hi, thanks for being interesting, i have repaired the code that you have published so it have no errors, but it doesn't work, you can work step by step and you can see that some functions of the winmm.dll are not returning the values as they are supposed to do, so i think the parameters given to these functions are not exact, like the function mixerGetLineInfo it always return a false value like 11

in MSDN they tell us that this function should return

Value                                  Description
MIXERR_INVALLINE              The audio line reference is invalid.
MMSYSERR_BADDEVICEID    The hmxobj parameter specifies an invalid device identifier.
MMSYSERR_INVALFLAG        One or more flags are invalid.
MMSYSERR_INVALHANDLE    The hmxobj parameter specifies an invalid handle.
MMSYSERR_INVALPARAM     One or more parameters are invalid.
MMSYSERR_NODRIVER No    mixer device is available for the object specified by hmxobj.

(from  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_mixergetlineinfo.asp)

but in our program it returns a long value i don't know why

i hope that can help


Imports System.Runtime.InteropServices
Public Class MicVolumeControl
#Region " Variables declartion "
    Private MicVolume As MIXERCONTROL
    Public rc As Long
    Public hmixer As Long
    Public ok As Boolean

    Private Const MMSYSERR_NOERROR = 0
    Private Const MAXPNAMELEN = 32
    Private Const MIXER_LONG_NAME_CHARS = 64
    Private Const MIXER_SHORT_NAME_CHARS = 16
    Private Const MIXER_SETCONTROLDETAILSF_VALUE = &H0&
    Private Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
    Private Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&
    Private Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
    Private Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
    Private Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&
    Private Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
    Private Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3)
    Private Const MIXERLINE_COMPONENTTYPE_SRC_LINE = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2)
    Private Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
    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_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1)
    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, ByVal 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, ByVal pumxID As Long, ByVal fdwId As Long) As Long
    Private Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (ByVal hmxobj As Long, ByVal pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Long) As Long
    Private Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Long, ByVal pmxl As MIXERLINE, ByVal fdwInfo As Long) As Long
    'Private Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Integer, ByVal pmxl As MIXERLINE, ByVal fdwInfo As Integer) As Integer
    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" (ByRef phmx As Integer, ByVal uMxId As Integer, ByVal dwCallback As Integer, ByVal dwInstance As Integer, ByVal fdwOpen As Integer) As Integer
    'Private Declare Function mixerOpen Lib "winmm.dll" (ByVal 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, ByVal pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long
    Private Declare Sub CopyStructFromPtr Lib "kernel32" Alias "RtlMoveMemory" (ByVal struct As MIXERCONTROL, ByVal ptr As Long, ByVal cb As Long)
    Private Declare Sub CopyPtrFromStruct Lib "kernel32" Alias "RtlMoveMemory" (ByVal ptr As Long, ByVal struct As Long, ByVal cb As Long)
    Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
    Private Declare Function GlobalLock Lib "kernel32" (ByVal hmem As Long) As Long
    Private Declare Function GlobalFree Lib "kernel32" (ByVal hmem As Long) As Long

    Private Structure MIXERCAPS
        Dim wMid As Integer                   '  manufacturer id
        Dim wPid As Integer                   '  product id
        Dim vDriverVersion As Long            '  version of the driver
        Dim szPname As String  '  product name
        Dim fdwSupport As Long                '  misc. support bits
        Dim cDestinations As Long             '  count of destinations
    End Structure

    Private Structure MIXERCONTROL
        Dim cbStruct As Long           '  size in Byte of MIXERCONTROL
        Dim dwControlID As Long        '  unique control id for mixer device
        Dim dwControlStructure As Long      '  MIXERCONTROL_CONTROLTYPE_xxx
        Dim fdwControl As Long          '  MIXERCONTROL_CONTROLF_xxx
        Dim cMultipleItems As Long      '  if MIXERCONTROL_CONTROLF_MULTIPLE set
        Dim szShortName As String            ' short name of control
        Dim szName As String     ' long name of control
        Dim lMinimum As Long           '  Minimum value
        Dim lMaximum As Long           '  Maximum value
        Dim reserved() As Long       '  reserved structure space
    End Structure

    Private Structure MIXERCONTROLDETAILS
        Dim cbStruct As Long       '  size in Byte of MIXERCONTROLDETAILS
        Dim dwControlID As Long    '  control id to get/set details on
        Dim cChannels As Long      '  number of channels in paDetails array
        Dim item As Long           '  hwndOwner or cMultipleItems
        Dim cbDetails As Long      '  size of _one_ details_XX struct
        Dim paDetails As Long      '  pointer to array of details_XX structs
    End Structure

    Private Structure MIXERCONTROLDETAILS_UNSIGNED
        Dim dwValue As Long        '  value of the control
    End Structure

    Private Structure MIXERLINE
        Dim cbStruct As Long               '  size of MIXERLINE structure
        Dim dwDestination As Long          '  zero based destination index
        Dim dwSource As Long               '  zero based source index (if source)
        Dim dwLineID As Long               '  unique line id for mixer device
        Dim fdwLine As Long                '  state/information about line
        Dim dwUser As Long                 '  driver specific information
        Dim dwComponentStructure As Long        '  component Structure line connects to
        Dim cChannels As Long              '  number of channels line supports
        Dim cConnections As Long           '  number of connections (possible)
        Dim cControls As Long              '  number of controls at this line
        Dim szShortName As String
        Dim szName As String
        Dim dwStructure As Long
        Dim dwDeviceID As Long
        Dim wMid As Integer
        Dim wPid As Integer
        Dim vDriverVersion As Long
        Dim szPname As String
        Dim dwComponentType As Long
    End Structure

    Private Structure MIXERLINECONTROLS
        Dim cbStruct As Long       '  size in Byte of MIXERLINECONTROLS
        Dim dwLineID As Long       '  line id (from MIXERLINE.dwLineID)
        '  MIXER_GETLINECONTROLSF_ONEBYID or
        Dim dwControl As Long      '  MIXER_GETLINECONTROLSF_ONEBYTYPE
        Dim cControls As Long      '  count of controls pmxctrl points to
        Dim cbmxctrl As Long       '  size in Byte of _one_ MIXERCONTROL
        Dim pamxctrl As Long       '  pointer to first MIXERCONTROL array
    End Structure
#End Region

#Region " Constructor "
    Sub New()
        rc = mixerOpen(hmixer, 0, 0, 0, 0)

        If ((MMSYSERR_NOERROR <> rc)) Then
            MsgBox("Couldn't open the mixer.")
            Exit Sub
        End If

        ok = GetVolumeControl()
    End Sub
#End Region

    ' This function attempts to obtain a mixer control. Returns True if successful.
    Private Function GetVolumeControl() As Boolean
        Dim mxlc As MIXERLINECONTROLS
        Dim mxl As MIXERLINE
        Dim hmem As Long

        mxl.cbStruct = Marshal.SizeOf(mxl)
        mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE

        ' Obtain a line corresponding to the component type
        rc = mixerGetLineInfo(hmixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)


        If (MMSYSERR_NOERROR = rc) Then

            mxlc.cbStruct = Len(mxlc)
            mxlc.dwLineID = mxl.dwLineID
            mxlc.dwControl = MIXERCONTROL_CONTROLTYPE_VOLUME
            mxlc.cControls = 1
            mxlc.cbmxctrl = Len(MicVolume)

            ' Allocate a buffer for the control
            hmem = GlobalAlloc(&H40, Len(MicVolume))
            mxlc.pamxctrl = GlobalLock(hmem)
            MicVolume.cbStruct = Len(MicVolume)

            ' Get the control
            rc = mixerGetLineControls(hmixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)

            If (MMSYSERR_NOERROR = rc) Then
                GetVolumeControl = True

                ' Copy the control into the destination structure
                CopyStructFromPtr(MicVolume, mxlc.pamxctrl, Len(MicVolume))
            Else
                GetVolumeControl = False
            End If
            GlobalFree(hmem)
            Exit Function
        End If

        GetVolumeControl = False
    End Function

    'This function sets the value for a volume control. Returns True if successful
    Public Function SetVolumeControl(ByVal volume As Long) As Boolean
        Dim mxcd As MIXERCONTROLDETAILS
        Dim vol As MIXERCONTROLDETAILS_UNSIGNED
        Dim hmem As Object

        mxcd.item = 0
        mxcd.dwControlID = MicVolume.dwControlID
        mxcd.cbStruct = Len(mxcd)
        mxcd.cbDetails = Len(vol)

        ' Allocate a buffer for the control value buffer
        hmem = GlobalAlloc(&H40, Len(vol))
        mxcd.paDetails = GlobalLock(hmem)
        mxcd.cChannels = 1
        vol.dwValue = volume

        ' Copy the data into the control value buffer
        CopyPtrFromStruct(mxcd.paDetails, vol.dwValue, Len(vol.dwValue))

        ' Set the control value
        rc = mixerSetControlDetails(hmixer, mxcd, MIXER_SETCONTROLDETAILSF_VALUE)

        GlobalFree(hmem)
        If (MMSYSERR_NOERROR = rc) Then
            SetVolumeControl = True
        Else
            SetVolumeControl = False
        End If
    End Function
End Class

waiting your assistance
Bye
0
 
pcnet2004Author Commented:
hi

I just want to tell you that time is not beside us, i am still waiting for an answer, if anybody else can help me please let him do it, quickly.

in your comment you had said that you don't know how to deal with vb.net, but my question was in VB.NET, i want to know: "this mean that no body in this site know how to deal with VB.Net ????" if the answer is yes, OK, i will stop my questions in VB.NET

But if the answer is NO, why i am talking to you, i need a VB.NET expert to help me.

Thanks
0
 
ajaikumarrCommented:
Hai,

I just want to let you know some thing... I does'nt mean to say I can't deal VB.NET i just want to say that i dont know how to deal this specific problem on vb.net (conversion of vb code to vb.net code).. Appart from this you must clearly know that here any experts can guide to solve the problem and not to do the homework of your problems. (you can see this on EE help page)... And also please try to ask question or give up comments in a polite manner... (I dont mind the words you typed to me but not all the people can take it in a simular way.)  Everybody here wants to help people who wanted to get some solution for their proplems... I did the same way and  helped you that's all... It's not a loss for me nor you...

Ok... Regarding to attract some other VB.NET export just open a new question and give minimul points and point the link to this question. so this will keep your question on top of all... Also you can see the top15 experts list on left hand side click on those name and check whether they had given any personal email address on their profile... If so send them a mail that you need a help on this area by providing this page link (url).

Any how best wishes.
Bye
Ajai
0
 
pcnet2004Author Commented:
hi again,

i don't know why things goes like this, i think because my comment was very strict and direct, i don't mean to ask in a inpolite manner, but i was really thinking that you might not be a VB.NET expert, maybe vb6, so please excuse me for this and forgett it.

In the other side, i think i am not asking to do my homework, and i am working to search every day to solve it without any help, and you can see that i repaired your work but still the problem it doesn't work, and if you want to know what i am doing now while writing my comment, i will tell you, i am downloading  DirectX9 SDK b for 218.00 MB (Imagine this), this download will finish after 5 minutes, it has been started from 20 hours, i think that my problem will be solved if i use the DirectSound, Do you think So? please tell me if this is wrong, but still i am sure that without DirectX there is a solution.

Don't be angry, my job is not to write inpolite comments, but beleive me, i was scared from the time i have to wait to get the help.

thanks
0
 
ajaikumarrCommented:
Hai,

Ok... I can understand your way of approach now... (I dont have any touch with you before i thought you are approaching in a arrogant manner...)

Sorry for this... To be Honest I have 0% knowledge in DirectX related functionalities... Any how will search for you and let you know...

Again i can suggest you to open up a sub link of this topic to get some more experts help.

Bye
Ajai
0
 
Daniellus83Commented:
Hello,

all of the code pasted above is useable, the idea of compiling in Visual basic (the old version ;-) ) and using in VB.NET is the most simple solution...
Here is the original VB6(!!) source (I downloaded somewhere form MSDN):  http://www.danieltrommel.com/download/volume.zip

This source have I altered to be usable within a Scrollbar in VB6... and next I did make a compilation (not .exe) in VB6 for you in the form of an ActiveX Dll wich you can IMPORT in VB.NET !!!


This is the way you can do this (VERY VERY simple!!) ::

step 1) download my "home-for-you-made" file:  http://www.danieltrommel.com/download/Mic_scroller.ocx

step 2) Start your VB.NET 2003,...

step 3) Select on the TOOLBOX (left on you .net 2003 interface) the section "My User Controls..."

step 4) Press now with your Right-mouse-button on the empty gray area on the toolbox and...

step 5) choose Add/Remove Items

step 6) In the new opened window choose the SECOND tabsheet "COM Components"

step 7) Press the button "Browse" and open your downloaded file (http://www.danieltrommel.com/download/Mic_scroller.ocx)

step 8) Now you should see a new icon appear on you Toolbox > My User Control

step 9) Add this component to your Form(s) like you would do with e.g. Labels, textboxes...

Final ) Run your program to find out that your now able to control your MIC!!!


-------------

:-) Daniƫl


Btw.: I am a new user.. and... can I get those 50 + 500 points?  '-\ ... At least I cracked the problem....
0
 
pcnet2004Author Commented:
Thanks Daniel for assistance but i just want to tell you that your user control is changing the mic volume, what i want is not the mic volume it is the mic recording volume, if you double-click on the icon of sound at the bottom of your screen you are entering the volume control, but if you click Options\Properties\Recording\OK, you will see the Recording volumes, here i want to control the microphone, and i will tell something, all the code listed in this question does not meet my request i have repaired the code and i have tried a lot to change, but i can't reach to the mic recording volume,

Thanks
0
 
Daniellus83Commented:

Here I am again, sorry for the wrong code the last time...

I've tried the last 2 days very very VERY VERY(!) hard to get this thing to work. I retyped most of the code in the OLD VB6 but I cannot get on my PC to my Record Volume of my Microphone (of WaveIn...). I figured all the code out,.. but still I wasn't able to get to the Mic's rec volume.

I tried to find you a written ActiveX component on the internet, the most you have to pay for but this one is very use-able:

http://www.dmm.cz/en/dmm_volume_dll.htm

They provide a .dll (with Vb.NET demo!!) with wich you should be able to fully control your Mic. I have checked it out, because it's a demo, it pops a 'DEMO windows at startup.

Try it and maybe you like it...
0
 
pcnet2004Author Commented:
thanks very match Daniel this library solved my problem, and thanks also to ajaikumarr
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 8
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now