List Info

Thread: Trouble getting mixer volume on Vista




Trouble getting mixer volume on Vista
country flaguser name
United States
2007-09-27 10:18:09

Hi,

I have a software package written in VB6 for Windows XP and Vista
based computers. It streams audio in from the internet and sends it to
the sound card. I also want to be able to control the volume level of
the sound card using the mixer settings. I get the volume level by
' Get the waveout volume control
ok = GetVolumeControl(hmixer, _
MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, _
MIXERCONTROL_CONTROLTYPE_VOLUME, _
volCtrl)
I then set the volume level with
SetVolumeControl hmixer, volCtrl, volCtrl.lMaximum

The volume mixer GetVolume routine and its entire header is included
at the bottom of this post.
The error occurs in the very last few lines of
' Obtain a line corresponding to the component type
rc = mixerGetLineInfo(hmixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)

MsgBox "mixerGetLineInfo Return Code = " & rc & vbCrLf & vbCrLf & _
"MMSYSERR_NOERROR=" & rc, vbOKOnly, "MIXER Return Code"

I added the msgbox to see why it was failing.

In all of the XP computers I have run this on, I get back the proper
error code of 0. Reagardless of whether I'm using the computers normal
sound card, or whether I have connected a Logitec USB
microphone/headset. And utilizing setvolume works as I hope, changing
the volume level of the audio to the speakers/headphone.

When I go to a Vista computer, I get exactly the same response (0)
when using the computers built in sound card. However, when I plug in
the same Logitec USB microphone/headset into the Vista USB port, I get
an error code 1024. And cannot get/set the volume of the device.

I am able to use directx just fine getting audio to and from the USB
headset, but I cannot control volume anymore in any USB headset in a
Vista computer. XP and 98SE are just fine.

A note, on both types of systems, and with or without the USB headset
plugged in, the streaming part to/from the sound card/headsets work
perfectly. It is just that in the USB headset variety, I am having to
disable my PC volume control, and direct the user to use the operating
systems audio level adjustments.... Would rather keep it seemless if I
can.

Does anyone have any clues, or can direct me to a forum that might be
able to help?
I'm going to post this to

Thanks,
John

Public Const MMSYSERR_NOERROR = 0
Public Const MAXPNAMELEN = 32
Public Const MIXER_LONG_NAME_CHARS = 64
Public Const MIXER_SHORT_NAME_CHARS = 16
Public Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
Public Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&
Public Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
Public Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
Public Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&

Public Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = _
(MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)

Public Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = _
(MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3)

Public Const MIXERLINE_COMPONENTTYPE_SRC_LINE = _
(MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2)

Public Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
Public Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000

Public Const MIXERCONTROL_CONTROLTYPE_FADER = _
(MIXERCONTROL_CT_CLASS_FADER Or _
MIXERCONTROL_CT_UNITS_UNSIGNED)

Public Const MIXERCONTROL_CONTROLTYPE_VOLUME = _
(MIXERCONTROL_CONTROLTYPE_FADER + 1)

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 mixerGetDevCaps Lib "winmm.dll" Alias
"mixerGetDevCapsA" _
(ByVal uMxId As Long, _
ByVal 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 mixerGetLineControls Lib "winmm.dll" Alias
"mixerGetLineControlsA" _
(ByVal hmxobj As Long, _
pmxlc As MIXERLINECONTROLS, _
ByVal fdwControls 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

Declare Function mixerMessage Lib "winmm.dll" _
(ByVal hmx As Long, _
ByVal uMsg As Long, _
ByVal dwParam1 As Long, _
ByVal dwParam2 As Long) 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 mixerSetControlDetails Lib "winmm.dll" _
(ByVal hmxobj As Long, _
pmxcd As MIXERCONTROLDETAILS, _
ByVal fdwDetails As Long) As Long

Declare Sub CopyStructFromPtr Lib "kernel32" Alias "RtlMoveMemory" _
(struct As Any, _
ByVal ptr As Long, _
ByVal cb As Long)

Declare Sub CopyPtrFromStruct Lib "kernel32" Alias "RtlMoveMemory" _
(ByVal ptr As Long, _
struct As Any, _
ByVal cb As Long)

Declare Function GlobalAlloc Lib "kernel32" _
(ByVal wFlags As Long, _
ByVal dwBytes As Long) As Long

Declare Function GlobalLock Lib "kernel32" _
(ByVal hmem As Long) As Long

Declare Function GlobalFree Lib "kernel32" _
(ByVal hmem As Long) 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 ' short name of
control
szName As String * MIXER_LONG_NAME_CHARS ' long name of control
lMinimum As Long ' Minimum value
lMaximum As Long ' Maximum value
Reserved(10) As Long ' reserved structure space
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 Long ' pointer to array of details_XX structs
End Type

Type MIXERCONTROLDETAILS_UNSIGNED
dwValue As Long ' value of the control
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
dwType As Long
dwDeviceID As Long
wMid As Integer
wPid As Integer
vDriverVersion As Long
szPname As String * MAXPNAMELEN
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 Long ' pointer to first MIXERCONTROL array
End Type

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function Name: GetVolumeControl
'
' Purpose: Tries to obtain a mixer control for Volume.
' Returns true if all went well, false if it couldn't
'
Function GetVolumeControl(ByVal hmixer As Long, _
ByVal componentType As Long, _
ByVal ctrlType As Long, _
ByRef mxc As MIXERCONTROL) As Boolean

' 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 rc As Long

mxl.cbStruct = Len(mxl)
mxl.dwComponentType = componentType

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

MsgBox "mixerGetLineInfo Return Code = " & rc & vbCrLf & vbCrLf & _
"MMSYSERR_NOERROR=" & rc, vbOKOnly, "MIXER Return Code"
.....
left out the rest.....

__._,_.___
.

__,_._,___
Re: Trouble getting mixer volume on Vista
country flaguser name
United States
2007-09-27 18:46:05

John Henry wrote:
>
> Hi,
>

John, I don't have the information at hand, but I have heard about a
vista 'feature' that sets a default output device for audio. This is
causing people all sorts of problems with USB microphones and headsets.

Given that there has been this sort of change within Vista, I would
guess that there have been some API changes to go with it. Sorry to not
be of much help, but perhaps it will give to a starting point for
looking up the necessary information.

Matt

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )