Solved

Problem implementing mixerGetLineControls in VB4

Posted on 1997-06-20
5
765 Views
Last Modified: 2009-07-29
Hi,

      I need to get the control ID of a particular mixer line. I managed to
open, close to device the function mixerGetLineControls failed to work.
mixerGetLineControls return me an error code of 11. What does it mean.
      Can anyone please help. Thanks.

code :

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 MIXERCONTROL       '  pointer to first MIXERCONTROL
array
End Type

Declare Function mixerGetLineControls Lib "winmm.dll" Alias
"mixerGetLineControlsA" (ByVal hmxobj As Long, pmxlc As       MIXERLINECONTROLS,
ByVal fdwControls As Long) As Long



Function GetCDFaderID() As Long
    Dim lRetVal As Long
    Dim mxrLine As MIXERLINE
    Dim mxrLineControls  As MIXERLINECONTROLS
      Dim mxrControl As MIXERCONTROL
   
   
    'set the size
    mxrLine.cbStruct = Len(mxrLine)
   
    mxrLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC
       
    'retrieve info about the the CDAudio line
    lRetVal = mixerGetLineInfo(lMixerHandle, mxrLine,
MIXER_GETLINEINFOF_COMPONENTTYPE)
   
    If lRetVal = 0 Then
        mxrLineControls.cbStruct = Len(mxrLineControls)
        mxrLineControls.dwLineID = mxrLine.dwLineID
        mxrLineControls.dwControl = MIXERCONTROL_CONTROLTYPE_VOLUME
'        mxrLineControls.cControls = mxrLine.cControls
        mxrLineControls.cControls = 1
       

        mxrLineControls.cbmxctrl = Len(mxrControl)

      =======================================
      the line below seems to be the main cuase for error
      ======================================      
      mxrLineControls.pamxctrl = mxrControl  'pointer to first MIXERCONTROL
array

       
        'retrieve the controls associated with the line
        lRetVal = mixerGetLineControls(lMixerHandle, mxrLineControls,       
MIXER_GETLINECONTROLSF_ONEBYTYPE)
       
        Debug.Print "GetLineControls: "; lRetVal
    End If
   
   
End Function
0
Comment
Question by:khoonking
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:y96andha
ID: 1427497
That error means: Invalid parameter passed

I think the problem is that the pamxctrl member should be a pointer to a MIXERCONTROL, not a MIXERCONTROL itself.

I have a working code to get the control, but I used a rather non-standard way to access the data. Would you like me to post the code as an answer?
0
 

Author Comment

by:khoonking
ID: 1427498
I wouid like to have your sample working code, definitely.
But any way, did you declare pmxctrl as long instead of MIXERCONTROL  and use VarPtr() to get the address. I did tried that but I encounter more problems.
Thanks for your help and waiting eagerly for your code.
0
 
LVL 5

Accepted Solution

by:
y96andha earned 100 total points
ID: 1427499
VarPtr doesn't even exist in my version of VB (4.0), so I declared it as a variable length string. Then I parsed it manually as a structure of the right kind. There must be an easier way to do it, but this does work.

------------------------------------ mixtst.frm
VERSION 4.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   8460
   ClientLeft      =   3375
   ClientTop       =   1920
   ClientWidth     =   6690
   Height          =   8865
   Left            =   3315
   LinkTopic       =   "Form1"
   ScaleHeight     =   8460
   ScaleWidth      =   6690
   Top             =   1575
   Width           =   6810
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   735
      Left            =   4080
      TabIndex        =   0
      Top             =   1320
      Width           =   2295
   End
End
Attribute VB_Name = "Form1"
Attribute VB_Creatable = False
Attribute VB_Exposed = False

'
Private Sub Command1_Click()
Dim ml As MIXERLINE
Dim mcs As MIXERCAPS
Dim mlc As MIXERLINECONTROLS
Dim mc As MIXERCONTROL
Dim mcd As MIXERCONTROLDETAILS
Dim buf(4096) As Byte
mcsize = LenB(mc) '17 * 4 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS

Dim status As Long
For i = 0 To mixerGetNumDevs - 1
    status = mixerGetDevCaps(i, mcs, LenB(mcs))
'    Print "mixerGetDevCaps"; status
    Print "mixer "; s(mcs.szPname)
    For j = 0 To mcs.cDestinations - 1
        ml.cbStruct = LenB(ml)
        ml.dwDestination = j
        ml.dwSource = 0
        status = mixerGetLineInfo(i, ml, MIXER_GETLINEINFOF_DESTINATION)
'        Print "  mixerGetLineInfo "; status
        Print "  destination line "; s(ml.szShortName); " = '"; s(ml.szName); "', controls: "; ml.cControls; ", connections: "; ml.cConnections
        mlc.cbStruct = LenB(mlc)
        mlc.dwLineID = ml.dwLineID
        mlc.cControls = ml.cControls
        mlc.cbmxctrl = LenB(mc)
        mlc.pamxctrl = String(LenB(mc) * ml.cControls, 0)
        status = mixerGetLineControls(i, mlc, MIXER_GETLINECONTROLSF_ALL)
 '       Print "  mixerGetLineControls "; status
        For k = 0 To ml.cControls - 1
            mc.dwControlID = tolong(Mid$(mlc.pamxctrl, k * mcsize + 1 + 4))
            mc.dwControlType = tolong(Mid$(mlc.pamxctrl, k * mcsize + 1 + 2 * 4))
            mc.szShortName = Mid$(mlc.pamxctrl, k * mcsize + 1 + 5 * 4, MIXER_SHORT_NAME_CHARS)
            mc.szName = Mid$(mlc.pamxctrl, k * mcsize + 1 + 5 * 4 + MIXER_SHORT_NAME_CHARS, MIXER_LONG_NAME_CHARS)
'            Print mc.szShortName
 '           Print mc.szName
'            Print hex$(mc.dwControlID)
 '           Print hex$(mc.dwControlType)
            Print "    control "; s(mc.szShortName); " = '"; s(mc.szName); "', ";
           
            Print "parsed type=[";
           
            If mc.fdwControl & MIXERCONTROL_CONTROLF_UNIFORM Then
                Print "Uniform ";
            End If
           
            Select Case (mc.dwControlType And MIXERCONTROL_CT_CLASS_MASK)
            Case MIXERCONTROL_CT_CLASS_CUSTOM
                Print "Custom ";
            Case MIXERCONTROL_CT_CLASS_FADER
                Print "Fader ";
            Case MIXERCONTROL_CT_CLASS_LIST
                Print "List ";
            Case MIXERCONTROL_CT_CLASS_METER
                Print "Meter ";
            Case MIXERCONTROL_CT_CLASS_NUMBER
                Print "Number ";
            Case MIXERCONTROL_CT_CLASS_SLIDER
                Print "Slider ";
            Case MIXERCONTROL_CT_CLASS_SWITCH
                Print "Switch ";
            Case MIXERCONTROL_CT_CLASS_TIME
                Print "Time ";
            Case Else
                Print "Unknown ("; hex$(mc.dwControlType And MIXERCONTROL_CT_CLASS_MASK); ") "
            End Select
           
            Select Case mc.dwControlType
            Case MIXERCONTROL_CONTROLTYPE_MIXER
                Print "Mixer ";
            Case MIXERCONTROL_CONTROLTYPE_MUX
                Print "Mux ";
            Case MIXERCONTROL_CONTROLTYPE_PEAKMETER
                Print "PeakMeter ";
                mcd.cbStruct = Len(mcd)
                mcd.dwControlID = mc.dwControlID
                If mc.fdwControl & MIXERCONTROL_CONTROLF_UNIFORM Then
                    mcd.cChannels = 1
                Else
                    mcd.cChannels = ml.cChannels
                End If
                mcd.cbDetails = 4
                mcd.item = 0
                mcd.paDetails = String(4 * mcd.cChannels, 0)
                status = mixerGetControlDetails(i, mcd, MIXER_GETCONTROLDETAILSF_VALUE)
                For m = 1 To mcd.cChannels
                    Print "peak["; m; "]="; tolong(Mid$(mcd.paDetails, m * 4)); " "
                Next m
            Case MIXERCONTROL_CONTROLTYPE_ONOFF
                Print "OnOff ";
            Case MIXERCONTROL_CONTROLTYPE_MUTE
                Print "Mute ";
            Case MIXERCONTROL_CONTROLTYPE_MONO
                Print "Mono ";
            Case MIXERCONTROL_CONTROLTYPE_LOUDNESS
                Print "Loudness ";
            Case MIXERCONTROL_CONTROLTYPE_STEREOENH
                Print "StereoEnh ";
            Case MIXERCONTROL_CONTROLTYPE_VOLUME
                Print "Volume ";
            Case MIXERCONTROL_CONTROLTYPE_BASS
                Print "Bass ";
            Case MIXERCONTROL_CONTROLTYPE_TREBLE
                Print "Treble ";
            Case MIXERCONTROL_CONTROLTYPE_EQUALIZER
                Print "Equalizer ";
            Case MIXERCONTROL_CONTROLTYPE_PAN
                Print "Pan ";
            Case MIXERCONTROL_CONTROLTYPE_QSOUNDPAN
                Print "QSoundPan ";
            End Select
           
           
            Print "]"
           
        Next k
       
        For l = 0 To ml.cConnections - 1
            ml.dwSource = l
            status = mixerGetLineInfo(i, ml, MIXER_GETLINEINFOF_SOURCE)
'            Print "    mixerGetLineInfo "; status
            Print "    source line "; s(ml.szShortName); " = '"; s(ml.szName); "', channels: "; ml.cChannels; ", controls: "; ml.cControls
           
            mlc.cbStruct = Len(mlc)
            mlc.dwLineID = ml.dwLineID
            mlc.cControls = ml.cControls
            mlc.cbmxctrl = LenB(mc)
            mlc.pamxctrl = String(LenB(mc) * ml.cControls, 0)
            status = mixerGetLineControls(i, mlc, MIXER_GETLINECONTROLSF_ALL)
'            Print "    mixerGetLineControls "; status
            For k = 0 To ml.cControls - 1
                mc.dwControlID = tolong(Mid$(mlc.pamxctrl, k * mcsize + 1 + 4))
                mc.dwControlType = tolong(Mid$(mlc.pamxctrl, k * mcsize + 1 + 2 * 4))
                mc.fdwControl = tolong(Mid$(mlc.pamxctrl, k * mcsize + 1 + 3 * 4))
                mc.szShortName = Mid$(mlc.pamxctrl, k * mcsize + 1 + 5 * 4, MIXER_SHORT_NAME_CHARS)
                mc.szName = Mid$(mlc.pamxctrl, k * mcsize + 1 + 5 * 4 + MIXER_SHORT_NAME_CHARS, MIXER_LONG_NAME_CHARS)
    '            Print mc.szShortName
     '           Print mc.szName
    '            Print hex$(mc.dwControlID)
     '           Print hex$(mc.dwControlType)
                Print "      control "; s(mc.szShortName); " = '"; s(mc.szName); "', ";
               
                Print "parsed type=[";
               
                If mc.fdwControl & MIXERCONTROL_CONTROLF_UNIFORM Then
                    Print "Uniform ";
                End If

               
                Select Case (mc.dwControlType And MIXERCONTROL_CT_CLASS_MASK)
                Case MIXERCONTROL_CT_CLASS_CUSTOM
                    Print "Custom ";
                Case MIXERCONTROL_CT_CLASS_FADER
                    Print "Fader ";
                Case MIXERCONTROL_CT_CLASS_LIST
                    Print "List ";
                Case MIXERCONTROL_CT_CLASS_METER
                    Print "Meter ";
                Case MIXERCONTROL_CT_CLASS_NUMBER
                    Print "Number ";
                Case MIXERCONTROL_CT_CLASS_SLIDER
                    Print "Slider ";
                Case MIXERCONTROL_CT_CLASS_SWITCH
                    Print "Switch ";
                Case MIXERCONTROL_CT_CLASS_TIME
                    Print "Time ";
                Case Else
                    Print "Unknown ("; hex$(mc.dwControlType And MIXERCONTROL_CT_CLASS_MASK); ") "
                End Select
               
                Select Case mc.dwControlType
                Case MIXERCONTROL_CONTROLTYPE_MIXER
                    Print "Mixer ";
                Case MIXERCONTROL_CONTROLTYPE_MUX
                    Print "Mux ";
                Case MIXERCONTROL_CONTROLTYPE_PEAKMETER
                    Print "PeakMeter ";
                    mcd.cbStruct = Len(mcd)
                    mcd.dwControlID = mc.dwControlID
                    If mc.fdwControl & MIXERCONTROL_CONTROLF_UNIFORM Then
                        mcd.cChannels = 1
                    Else
                        mcd.cChannels = ml.cChannels
                    End If
                    mcd.cbDetails = 4
                    mcd.item = 0
                    mcd.paDetails = String(4 * mcd.cChannels, 0)
                    status = mixerGetControlDetails(i, mcd, MIXER_GETCONTROLDETAILSF_VALUE)
                    For m = 1 To mcd.cChannels
                        Print "peak["; m; "]="; tolong(Mid$(mcd.paDetails, m * 4)); " "
                    Next m
                Case MIXERCONTROL_CONTROLTYPE_ONOFF
                    Print "OnOff ";
                Case MIXERCONTROL_CONTROLTYPE_MUTE
                    Print "Mute ";
                Case MIXERCONTROL_CONTROLTYPE_MONO
                    Print "Mono ";
                Case MIXERCONTROL_CONTROLTYPE_LOUDNESS
                    Print "Loudness ";
                Case MIXERCONTROL_CONTROLTYPE_STEREOENH
                    Print "StereoEnh ";
                Case MIXERCONTROL_CONTROLTYPE_VOLUME
                    Print "Volume ";
                Case MIXERCONTROL_CONTROLTYPE_BASS
                    Print "Bass ";
                Case MIXERCONTROL_CONTROLTYPE_TREBLE
                    Print "Treble ";
                Case MIXERCONTROL_CONTROLTYPE_EQUALIZER
                    Print "Equalizer ";
                Case MIXERCONTROL_CONTROLTYPE_PAN
                    Print "Pan ";
                Case MIXERCONTROL_CONTROLTYPE_QSOUNDPAN
                    Print "QSoundPan ";
                End Select
           
           
                Print "]"
           
            Next k
        Next l
    Next j
Next i
End Sub
-----------------------------------------------------------------


------------------------------------ mixtst.bas
Attribute VB_Name = "Module1"
Public Const MIXER_LONG_NAME_CHARS = 64
Public Const MIXER_SHORT_NAME_CHARS = 16
Public Const MAXPNAMELEN = 32  '  max product name length (including NULL)
Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long
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
Declare Function mixerClose Lib "winmm.dll" (ByVal hmx As Long) As Long
Declare Function mixerGetControlDetails Lib "winmm.dll" Alias "mixerGetControlDetailsA" (ByVal hmxobj As Long, pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long
Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (ByVal hmxobj As Long, pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Long) As Long
Declare Function mixerGetDevCaps Lib "winmm.dll" Alias "mixerGetDevCapsA" (ByVal uMxId As Long, pmxcaps As MIXERCAPS, ByVal cbmxcaps As Long) As Long
Declare Function mixerGetID Lib "winmm.dll" (ByVal hmxobj As Long, pumxID As Long, ByVal fdwId As Long) As Long
Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Long, pmxl As MIXERLINE, ByVal fdwInfo As Long) As Long
Declare Function mixerGetNumDevs Lib "winmm.dll" () As Long
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
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 As String * MIXER_SHORT_NAME_CHARS
        szName As String * MIXER_LONG_NAME_CHARS
        Bounds1 As Long
        Bounds2 As Long
        Bounds3 As Long
        Bounds4 As Long
        Bounds5 As Long
        Bounds6 As Long
        Metrics1 As Long
        Metrics2 As Long
        Metrics3 As Long
        Metrics4 As Long
        Metrics5 As Long
        Metrics6 As Long
End Type
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 String 'Long      '  pointer to array of details_XX structs
End Type
Type MIXERCONTROLDETAILS_BOOLEAN
        fValue As Long
End Type
Type MIXERCONTROLDETAILS_LISTTEXT
        dwParam1 As Long
        dwParam2 As Long
        szName As String * MIXER_LONG_NAME_CHARS
End Type
Type MIXERCONTROLDETAILS_SIGNED
        lValue As Long
End Type
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
Type MIXERCONTROLDETAILS_UNSIGNED
        dwValue As Long
End Type
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
        lpTarget As Target
End Type
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 String 'MIXERCONTROL       '  pointer to first MIXERCONTROL array
End Type
Type buf192
    buf(192) As Byte
End Type
Public Const MIXER_GETCONTROLDETAILSF_LISTTEXT = &H1&
Public Const MIXER_GETCONTROLDETAILSF_QUERYMASK = &HF&
Public Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&
Public Const MIXER_GETLINECONTROLSF_ALL = &H0&
Public Const MIXER_GETLINECONTROLSF_ONEBYID = &H1&
Public Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
Public Const MIXER_GETLINECONTROLSF_QUERYMASK = &HF&
Public Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
Public Const MIXER_GETLINEINFOF_DESTINATION = &H0&
Public Const MIXER_GETLINEINFOF_LINEID = &H2&
Public Const MIXER_GETLINEINFOF_QUERYMASK = &HF&
Public Const MIXER_GETLINEINFOF_SOURCE = &H1&
Public Const MIXER_GETLINEINFOF_TARGETTYPE = &H4&
Public Const MIXER_OBJECTF_AUX = &H50000000
Public Const MIXER_OBJECTF_HANDLE = &H80000000
Public Const MIXER_OBJECTF_MIDIIN = &H40000000
Public Const MIXER_OBJECTF_MIDIOUT = &H30000000
Public Const MIXER_OBJECTF_MIXER = &H0&
Public Const MIXER_OBJECTF_WAVEIN = &H20000000
Public Const MIXER_OBJECTF_WAVEOUT = &H10000000
Public Const MIXERCONTROL_CT_CLASS_CUSTOM = &H0&
Public Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
Public Const MIXERCONTROL_CT_CLASS_LIST = &H70000000
Public Const MIXERCONTROL_CT_CLASS_MASK = &HF0000000
Public Const MIXERCONTROL_CT_CLASS_METER = &H10000000
Public Const MIXERCONTROL_CT_CLASS_NUMBER = &H30000000
Public Const MIXERCONTROL_CT_CLASS_SLIDER = &H40000000
Public Const MIXERCONTROL_CT_CLASS_SWITCH = &H20000000
Public Const MIXERCONTROL_CT_CLASS_TIME = &H60000000
Public Const MIXERCONTROL_CT_SC_LIST_MULTIPLE = &H1000000
Public Const MIXERCONTROL_CT_SC_LIST_SINGLE = &H0&
Public Const MIXERCONTROL_CT_SC_METER_POLLED = &H0&
Public Const MIXERCONTROL_CT_SC_SWITCH_BOOLEAN = &H0&
Public Const MIXERCONTROL_CT_SC_SWITCH_BUTTON = &H1000000
Public Const MIXERCONTROL_CT_SC_TIME_MICROSECS = &H0&
Public Const MIXERCONTROL_CT_SC_TIME_MILLISECS = &H1000000
Public Const MIXERCONTROL_CT_SUBCLASS_MASK = &HF000000
Public Const MIXERCONTROL_CT_UNITS_BOOLEAN = &H10000
Public Const MIXERCONTROL_CT_UNITS_CUSTOM = &H0&
Public Const MIXERCONTROL_CT_UNITS_DECIBELS = &H40000 '  in 10ths
Public Const MIXERCONTROL_CT_UNITS_MASK = &HFF0000
Public Const MIXERCONTROL_CT_UNITS_PERCENT = &H50000 '  in 10ths
Public Const MIXERCONTROL_CT_UNITS_SIGNED = &H20000
Public Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000
Public Const MIXER_OBJECTF_HMIDIIN = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIIN)
Public Const MIXER_OBJECTF_HMIDIOUT = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIDIOUT)
Public Const MIXER_OBJECTF_HMIXER = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)
Public Const MIXER_OBJECTF_HWAVEIN = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEIN)
Public Const MIXER_OBJECTF_HWAVEOUT = (MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_WAVEOUT)
Public Const MIXER_SETCONTROLDETAILSF_CUSTOM = &H1&
Public Const MIXER_SETCONTROLDETAILSF_QUERYMASK = &HF&
Public Const MIXER_SETCONTROLDETAILSF_VALUE = &H0&
Public Const MIXERCONTROL_CONTROLF_DISABLED = &H80000000
Public Const MIXERCONTROL_CONTROLF_MULTIPLE = &H2&
Public Const MIXERCONTROL_CONTROLF_UNIFORM = &H1&
Public Const MIXERCONTROL_CONTROLTYPE_FADER = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Public Const MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT = (MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_SC_LIST_MULTIPLE Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Public Const MIXERCONTROL_CONTROLTYPE_SINGLESELECT = (MIXERCONTROL_CT_CLASS_LIST Or MIXERCONTROL_CT_SC_LIST_SINGLE Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Public Const MIXERCONTROL_CONTROLTYPE_SIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_SIGNED)
Public Const MIXERCONTROL_CONTROLTYPE_SLIDER = (MIXERCONTROL_CT_CLASS_SLIDER Or MIXERCONTROL_CT_UNITS_SIGNED)
Public Const MIXERCONTROL_CONTROLTYPE_BOOLEAN = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_SC_SWITCH_BOOLEAN Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Public Const MIXERCONTROL_CONTROLTYPE_BOOLEANMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Public Const MIXERCONTROL_CONTROLTYPE_BUTTON = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_SC_SWITCH_BUTTON Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Public Const MIXERCONTROL_CONTROLTYPE_CUSTOM = (MIXERCONTROL_CT_CLASS_CUSTOM Or MIXERCONTROL_CT_UNITS_CUSTOM)
Public Const MIXERCONTROL_CONTROLTYPE_DECIBELS = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_DECIBELS)
Public Const MIXERCONTROL_CONTROLTYPE_MICROTIME = (MIXERCONTROL_CT_CLASS_TIME Or MIXERCONTROL_CT_SC_TIME_MICROSECS Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Public Const MIXERCONTROL_CONTROLTYPE_MILLITIME = (MIXERCONTROL_CT_CLASS_TIME Or MIXERCONTROL_CT_SC_TIME_MILLISECS Or MIXERCONTROL_CT_UNITS_UNSIGNED)

Public Const MIXERCONTROL_CONTROLTYPE_MIXER = (MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT + 1)

Public Const MIXERCONTROL_CONTROLTYPE_MUX = (MIXERCONTROL_CONTROLTYPE_SINGLESELECT + 1)

Public Const MIXERCONTROL_CONTROLTYPE_PAN = (MIXERCONTROL_CONTROLTYPE_SLIDER + 1)
Public Const MIXERCONTROL_CONTROLTYPE_QSOUNDPAN = (MIXERCONTROL_CONTROLTYPE_SLIDER + 2)

Public Const MIXERCONTROL_CONTROLTYPE_PEAKMETER = (MIXERCONTROL_CONTROLTYPE_SIGNEDMETER + 1)

Public Const MIXERCONTROL_CONTROLTYPE_ONOFF = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 1)
Public Const MIXERCONTROL_CONTROLTYPE_MUTE = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 2)
Public Const MIXERCONTROL_CONTROLTYPE_MONO = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 3)
Public Const MIXERCONTROL_CONTROLTYPE_LOUDNESS = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 4)
Public Const MIXERCONTROL_CONTROLTYPE_STEREOENH = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 5)

Public Const MIXERCONTROL_CONTROLTYPE_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1)
Public Const MIXERCONTROL_CONTROLTYPE_BASS = (MIXERCONTROL_CONTROLTYPE_FADER + 2)
Public Const MIXERCONTROL_CONTROLTYPE_TREBLE = (MIXERCONTROL_CONTROLTYPE_FADER + 3)
Public Const MIXERCONTROL_CONTROLTYPE_EQUALIZER = (MIXERCONTROL_CONTROLTYPE_FADER + 4)

Public Const MIXERCONTROL_CONTROLTYPE_UNSIGNED = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Public Const MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Public Const MIXERCONTROL_CONTROLTYPE_PERCENT = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_PERCENT)
Public Const MIXERCONTROL_CONTROLTYPE_SIGNED = (MIXERCONTROL_CT_CLASS_NUMBER Or MIXERCONTROL_CT_UNITS_SIGNED)

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

Function hex$(d As Long)
    Dim s As String
    Dim i As Integer
    s = ""
    For i = 7 To 0 Step -1
        s = s & hexdig((d / (2 ^ (i * 4))) And &HF)
    Next i
    hex$ = s
End Function

Function hexdig$(d As Long)
    d = d And &HF
    If d >= 10 Then hexdig$ = Chr(Asc("A") + d - 10) Else hexdig = Chr(Asc("0") + d)
End Function


Function s(sz As String) As String
    If InStr(sz, Chr(0)) Then
        s = Left$(sz, InStr(sz, Chr(0)) - 1)
    Else
        s = sz
    End If
End Function


Function tolong(s As String) As Long
If Asc(Mid$(s, 4)) And &H80 Then
    tolong = &H80000000 + (Asc(Mid$(s, 4)) And &H7F) * 2 ^ 24 + Asc(Mid$(s, 3)) * 2 ^ 16 + Asc(Mid$(s, 2)) * 2 ^ 8 + Asc(Mid$(s, 1))
Else
    tolong = (Asc(Mid$(s, 4)) And &H7F) * 2 ^ 24 + Asc(Mid$(s, 3)) * 2 ^ 16 + Asc(Mid$(s, 2)) * 2 ^ 8 + Asc(Mid$(s, 1))
End If
End Function
-----------------------------------------------------------------





0
 

Author Comment

by:khoonking
ID: 1427500
Thanks for your source code. I agree that the main problem is due to the structure MIXERCONTROL. The structure declared that come with "Microsoft VB4 API Text Viewer" is wrong. The union structure for Bounds and Metrics was not declared coorectly. Somehow, they forgot about the DWORD dwReserved that appear in both the union structure.

I had declared  MIXERLINECONTROLS as follow
        Type MIXERLINECONTROLS     cbStruct As Long
        dwLineID As Long
        dwControl As Long      
        cControls As Long      
        cbmxctrl As Long
        pamxctrl As Long
End Type

pamxctrl was declared as long so that it can accept a pointer.

Dim mxrControl As MIXERCONTROL

Later, I use VarPtr(mxrcontrol) to get the address. and use  MoveMemory to copy the data to the structure mxrControl.

        mxrLineControls.cbmxctrl = Len(mxrControl)
        mxrLineControls.pamxctrl = VarPtr(mxrControl)
        lRetVal = mixerGetLineControls(lMixerHandle, mxrLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE)
       
        MoveMemory mxrControl, mxrLineControls.pamxctrl, Len(mxrControl)


''''''''''''''''''''''''''''''''''''''''''''''''''''
'undocumented function in VB4
'it will return a pointer to the variable you passed
Declare Function VarPtr Lib "vb40032.dll" (lpvoid As Any) As Long

Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (dest As Any, ByVal Source As Long, ByVal length As Long)

0
 

Expert Comment

by:sinha_sandeep
ID: 3660954
That error means: Invalid parameter passed

I have a working code that i sand

 Const MIXER_SHORT_NAME_CHARS = 16
Const MIXER_LONG_NAME_CHARS = 64
 Const MAXPNAMELEN = 32  '  max product name length (including NULL)
 Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&
  Const MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC = (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 5)
 Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
  Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
 Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000

 Const MIXERCONTROL_CONTROLTYPE_FADER = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)

 Const MIXERCONTROL_CONTROLTYPE_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1)
Private Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&


'****************************erro cons
Private Const MIXERR_BASE = 1024
Private Const MMSYSERR_BASE = 0

 Const MIXERR_INVALCONTROL = (MIXERR_BASE + 1)
 Const MIXERR_INVALLINE = (MIXERR_BASE + 0)
 Const MMSYSERR_BADDEVICEID = (MMSYSERR_BASE + 2)  '  device ID out of range
 Const MMSYSERR_INVALFLAG = (MMSYSERR_BASE + 10) '  invalid flag passed
 Const MMSYSERR_INVALHANDLE = (MMSYSERR_BASE + 5)  '  device handle is invalid
 Const MMSYSERR_INVALPARAM = (MMSYSERR_BASE + 11) '  invalid parameter passed
 Const MMSYSERR_NODRIVER = (MMSYSERR_BASE + 6)  '  no device driver present

'**************************end cont
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 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 As String * MIXER_SHORT_NAME_CHARS
        szName As String * MIXER_LONG_NAME_CHARS
        Bounds(1 To 6) As Long     '  Longest member of the Bounds union
        Metrics(1 To 6) As Long    '  Longest member of the Metrics union
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 MIXERCONTROL       '  pointer to first MIXERCONTROL array
End Type
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 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 mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (ByVal hmxobj As Long, pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Long) As Long



Public Function GetCDFaderID() As Long
    Dim lRetVal As Long
    Dim mxrLine As MIXERLINE
    Dim mxrLineControls  As MIXERLINECONTROLS
Dim mxrControl As MIXERCONTROL, rc As Long, lMixerHandle As Long
   
 rc = mixerOpen(lMixerHandle, 0, 0, 0, 0)
 If rc <> 0 Then
 Exit Function
 End If
    'set the size
    mxrLine.cbStruct = Len(mxrLine)
   
    mxrLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC
       
    'retrieve info about the the CDAudio line
    lRetVal = mixerGetLineInfo(lMixerHandle, mxrLine, MIXER_GETLINEINFOF_COMPONENTTYPE)
   
    If lRetVal = 0 Then
        mxrLineControls.cbStruct = Len(mxrLineControls)
        mxrLineControls.dwLineID = mxrLine.dwLineID
        mxrLineControls.dwControl = MIXERCONTROL_CONTROLTYPE_VOLUME
'        mxrLineControls.cControls = mxrLine.cControls
        mxrLineControls.cControls = 1
       

        mxrLineControls.cbmxctrl = Len(mxrControl)

'=======================================
'the line below seems to be the main cuase for error
'======================================
mxrLineControls.pamxctrl = mxrControl  'pointer to first MIXERCONTROL array

       
        'retrieve the controls associated with the line
        lRetVal = mixerGetLineControls(lMixerHandle, mxrLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE)
       
        Select Case lRetVal
        Case MIXERR_INVALCONTROL
 Case MIXERR_INVALLINE
 MsgBox "MIXERR_INVALLINE"
 Case MMSYSERR_BADDEVICEID
  MsgBox "MMSYSERR_BADDEVICEID"
 Case MMSYSERR_INVALFLAG
 MsgBox "MMSYSERR_INVALFLAG"
 Case MMSYSERR_INVALHANDLE
 MsgBox "MMSYSERR_INVALHANDLE"
 Case MMSYSERR_INVALPARAM
 MsgBox "MMSYSERR_INVALPARAM"
 Case MMSYSERR_NODRIVER
 MsgBox "MMSYSERR_NODRIVER"
        End Select
    End If
   
   
End Function




0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now