Announcement

Collapse
No announcement yet.

vb.net code for volume control

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • vb.net code for volume control

    hello vb.net coders.. i've been trying to control volume thru vb.net and i cannot see how to do that. I searched but all i could find was vb6 code. i know several of you are working with vb.net... is there any sample source code they can send me or post here for others to be able to use? thanx
    -VIA EPIA M10000/512MB/40GB HD
    -DWW motorized 7'
    -BU 303 GPS w/iGuidance/ CF
    -Opus90w
    -Belkin Bluetooth
    -Pioneer HU

    [||||||||||] 95% done

  • #2
    i've got it at home... (at work right now). it's pretty straight forward. i'll post it tonight (around 6PM EST).
    EWF, HORM, MinLogon on XP.

    Zotac ION Atom N330, 2GB low-profile RAM, M3-ATX
    Win Embedded Std 2011 RC
    OCZ Vertex Turbo 30GB SSD
    Lilliput 629 Transflective, WRX Screen Mount
    BlueSoleil BT, i-Blue GM-2 GPS, DirectedHD Radio, Andrea Mic
    VoomPC 2

    Comment


    • #3
      thnx
      -VIA EPIA M10000/512MB/40GB HD
      -DWW motorized 7'
      -BU 303 GPS w/iGuidance/ CF
      -Opus90w
      -Belkin Bluetooth
      -Pioneer HU

      [||||||||||] 95% done

      Comment


      • #4
        okay, the one i use is in c#. can't remember where I found it online since it took a **** load of googling. i didn't feel like writing all the marshalling stuff myself, but this is the best one i found. shouldn't be hard to convert it to Vb.net.

        Code:
        using System; 
        using System.Runtime.InteropServices; 
        
        namespace PhidgetTest
        {
        	public class AudioMixerHelper 
        	{ 
        		public const int MMSYSERR_NOERROR = 0; 
        		public const int MAXPNAMELEN = 32; 
        		public const int MIXER_LONG_NAME_CHARS = 64; 
        		public const int MIXER_SHORT_NAME_CHARS = 16; 
        		public const int MIXER_GETLINEINFOF_COMPONENTTYPE = 0x3; 
        		public const int MIXER_GETCONTROLDETAILSF_VALUE = 0x0; 
        		public const int MIXER_GETLINECONTROLSF_ONEBYTYPE = 0x2; 
        		public const int MIXER_SETCONTROLDETAILSF_VALUE = 0x0; 
        		public const int MIXERLINE_COMPONENTTYPE_DST_FIRST = 0x0; 
        		public const int MIXERLINE_COMPONENTTYPE_SRC_FIRST = 0x1000; 
        		public const int MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = 
        			(MIXERLINE_COMPONENTTYPE_DST_FIRST + 4); 
        		public const int MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = 
        			(MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3); 
        		public const int MIXERLINE_COMPONENTTYPE_SRC_LINE = 
        			(MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2); 
        		public const int MIXERCONTROL_CT_CLASS_FADER = 0x50000000; 
        		public const int MIXERCONTROL_CT_UNITS_UNSIGNED = 0x30000; 
        		public const int MIXERCONTROL_CONTROLTYPE_FADER = 
        			(MIXERCONTROL_CT_CLASS_FADER | MIXERCONTROL_CT_UNITS_UNSIGNED); 
        		public const int MIXERCONTROL_CONTROLTYPE_VOLUME = 
        			(MIXERCONTROL_CONTROLTYPE_FADER + 1); 
        
        		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
        		private static extern int mixerClose (int hmx); 
        		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
        		private static extern int mixerGetControlDetailsA (int hmxobj,ref 
        			MIXERCONTROLDETAILS pmxcd , int fdwDetails); 
        		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
        		private static extern int mixerGetDevCapsA(int uMxId, MIXERCAPS 
        			pmxcaps, int cbmxcaps); 
        		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
        		private static extern int mixerGetID (int hmxobj, int pumxID, int 
        			fdwId); 
        		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
        		private static extern int mixerGetLineControlsA (int hmxobj,ref 
        			MIXERLINECONTROLS pmxlc, int fdwControls); 
        		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
        		private static extern int mixerGetLineInfoA (int hmxobj,ref 
        			MIXERLINE pmxl , int fdwInfo); 
        		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
        		private static extern int mixerGetNumDevs(); 
        		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
        		private static extern int mixerMessage(int hmx , int uMsg , int 
        			dwParam1 , int dwParam2); 
        		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
        		private static extern int mixerOpen (out int phmx , int uMxId , 
        			int dwCallback , int dwInstance , int fdwOpen); 
        		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
        		private static extern int mixerSetControlDetails(int hmxobj ,ref 
        			MIXERCONTROLDETAILS pmxcd , int fdwDetails); 
        
        		public struct MIXERCAPS 
        		{ 
        			public int wMid; 
        			public int wPid; 
        			public int vDriverVersion; 
        			[MarshalAs(UnmanagedType.ByValTStr, SizeConst=MAXPNAMELEN)] 
        			public string szPname; 
        			public int fdwSupport; 
        			public int cDestinations; 
        		} 
        
        		public struct MIXERCONTROL 
        		{ 
        			public int cbStruct; 
        			public int dwControlID; 
        			public int dwControlType; 
        			public int fdwControl; 
        			public int cMultipleItems; 
        			[MarshalAs( UnmanagedType.ByValTStr, 
        				 SizeConst=MIXER_SHORT_NAME_CHARS)] 
        			public string szShortName ; 
        			[MarshalAs( UnmanagedType.ByValTStr, 
        				 SizeConst=MIXER_LONG_NAME_CHARS)] 
        			public string szName; 
        			public int lMinimum; 
        			public int lMaximum; 
        			[MarshalAs(UnmanagedType.U4, SizeConst=10)] 
        			public int reserved; 
        		} 
        
        		public struct MIXERCONTROLDETAILS 
        		{ 
        			public int cbStruct; 
        			public int dwControlID; 
        			public int cChannels; 
        			public int item; 
        			public int cbDetails; 
        			public IntPtr paDetails; 
        		} 
        
        		public struct MIXERCONTROLDETAILS_UNSIGNED 
        		{ 
        			public int dwValue; 
        		} 
        
        		public struct MIXERLINE 
        		{ 
        			public int cbStruct; 
        			public int dwDestination; 
        			public int dwSource; 
        			public int dwLineID; 
        			public int fdwLine; 
        			public int dwUser; 
        			public int dwComponentType; 
        			public int cChannels; 
        			public int cConnections; 
        			public int cControls; 
        			[MarshalAs(UnmanagedType.ByValTStr, 
        				 SizeConst=MIXER_SHORT_NAME_CHARS)] 
        			public string szShortName; 
        			[MarshalAs(UnmanagedType.ByValTStr, 
        				 SizeConst=MIXER_LONG_NAME_CHARS )] 
        			public string szName; 
        			public int dwType; 
        			public int dwDeviceID; 
        			public int wMid; 
        			public int wPid; 
        			public int vDriverVersion ; 
        			[MarshalAs(UnmanagedType.ByValTStr, SizeConst=MAXPNAMELEN)] 
        			public string szPname ; 
        		} 
        
        		public struct MIXERLINECONTROLS 
        		{ 
        			public int cbStruct; 
        			public int dwLineID; 
        
        			public int dwControl; 
        			public int cControls; 
        			public int cbmxctrl; 
        			public IntPtr pamxctrl; 
        		} 
        
        		private static bool GetVolumeControl(int hmixer, int componentType, 
        			int ctrlType, out MIXERCONTROL mxc, out int vCurrentVol) 
        		{ 
        			// This function attempts to obtain a mixer control. 
        			// Returns True if successful. 
        			MIXERLINECONTROLS mxlc = new MIXERLINECONTROLS(); 
        			MIXERLINE mxl = new MIXERLINE(); 
        			MIXERCONTROLDETAILS pmxcd = new MIXERCONTROLDETAILS(); 
        			MIXERCONTROLDETAILS_UNSIGNED du = new 
        				MIXERCONTROLDETAILS_UNSIGNED(); 
        			mxc = new MIXERCONTROL(); 
        			int rc; 
        			bool retValue; 
        			vCurrentVol = -1; 
        
        			mxl.cbStruct = Marshal.SizeOf(mxl); 
        			mxl.dwComponentType = componentType; 
        
        			rc = mixerGetLineInfoA(hmixer,ref mxl, 
        				MIXER_GETLINEINFOF_COMPONENTTYPE ); 
        
        			if(MMSYSERR_NOERROR == rc) 
        			{ 
        				int sizeofMIXERCONTROL = 152; 
        				int ctrl = Marshal.SizeOf(typeof(MIXERCONTROL)); 
        				mxlc.pamxctrl = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL); 
        				mxlc.cbStruct = Marshal.SizeOf(mxlc); 
        				mxlc.dwLineID = mxl.dwLineID; 
        				mxlc.dwControl = ctrlType; 
        				mxlc.cControls = 1; 
        				mxlc.cbmxctrl = sizeofMIXERCONTROL; 
        
        				// Allocate a buffer for the control 
        				mxc.cbStruct = sizeofMIXERCONTROL; 
        
        				// Get the control 
        				rc = mixerGetLineControlsA(hmixer,ref mxlc, 
        					MIXER_GETLINECONTROLSF_ONEBYTYPE); 
        
        				if(MMSYSERR_NOERROR == rc) 
        				{ 
        					retValue = true; 
        
        					// Copy the control into the destination structure 
        					mxc = (MIXERCONTROL)Marshal.PtrToStructure( 
        						mxlc.pamxctrl,typeof(MIXERCONTROL)); 
        				} 
        				else 
        				{ 
        					retValue = false; 
        				} 
        				int sizeofMIXERCONTROLDETAILS = 
        					Marshal.SizeOf(typeof(MIXERCONTROLDETAILS)); 
        				int sizeofMIXERCONTROLDETAILS_UNSIGNED = 
        					Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED)); 
        				pmxcd.cbStruct = sizeofMIXERCONTROLDETAILS; 
        				pmxcd.dwControlID = mxc.dwControlID; 
        				pmxcd.paDetails = 
        
        					Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED) ; 
        				pmxcd.cChannels = 1; 
        				pmxcd.item = 0; 
        				pmxcd.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED; 
        
        				rc = mixerGetControlDetailsA(hmixer,ref pmxcd, 
        					MIXER_GETCONTROLDETAILSF_VALUE); 
        
        				du = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure( 
        					pmxcd.paDetails, typeof(MIXERCONTROLDETAILS_UNSIGNED)); 
        
        				vCurrentVol = du.dwValue; 
        
        				return retValue; 
        			} 
        
        			retValue = false; 
        			return retValue; 
        		} 
        
        		private static bool SetVolumeControl(int hmixer, MIXERCONTROL mxc, 
        			int volume) 
        		{ 
        			// This function sets the value for a volume control. 
        			// Returns True if successful 
        
        			bool retValue; 
        			int rc; 
        			MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS(); 
        			MIXERCONTROLDETAILS_UNSIGNED vol = new 
        				MIXERCONTROLDETAILS_UNSIGNED(); 
        
        			mxcd.item = 0; 
        			mxcd.dwControlID = mxc.dwControlID; 
        			mxcd.cbStruct = Marshal.SizeOf(mxcd); 
        			mxcd.cbDetails = Marshal.SizeOf(vol); 
        
        			// Allocate a buffer for the control value buffer 
        			mxcd.cChannels = 1; 
        			vol.dwValue = volume; 
        
        			// Copy the data into the control value buffer 
        			mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf( 
        				typeof(MIXERCONTROLDETAILS_UNSIGNED))); 
        			Marshal.StructureToPtr(vol, mxcd.paDetails,false); 
        
        			// Set the control value 
        			rc = mixerSetControlDetails(hmixer,ref mxcd, 
        				MIXER_SETCONTROLDETAILSF_VALUE); 
        
        			if(MMSYSERR_NOERROR == rc) 
        			{ 
        				retValue = true; 
        			} 
        			else 
        			{ 
        				retValue = false; 
        			} return retValue; 
        		} 
        
        		public static int GetVolume() 
        		{ 
        			int mixer; 
        			MIXERCONTROL volCtrl = new MIXERCONTROL(); 
        			int currentVol; 
        			mixerOpen(out mixer,0 ,0 ,0, 0); 
        			int type = MIXERCONTROL_CONTROLTYPE_VOLUME; 
        			GetVolumeControl(mixer, 
        				MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,type,out volCtrl, out 
        				currentVol); 
        			mixerClose(mixer); 
        
        			return currentVol; 
        		} 
        
        		public static void SetVolume(int vVolume) 
        		{ 
        			int mixer; 
        			MIXERCONTROL volCtrl = new MIXERCONTROL(); 
        			int currentVol; 
        			mixerOpen(out mixer,0 ,0 ,0, 0); 
        			int type = MIXERCONTROL_CONTROLTYPE_VOLUME; 
        			GetVolumeControl(mixer, 
        				MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,type,out volCtrl, out 
        				currentVol); 
        			if(vVolume > volCtrl.lMaximum) vVolume = volCtrl.lMaximum; 
        			if(vVolume < volCtrl.lMinimum) vVolume = volCtrl.lMinimum; 
        			SetVolumeControl(mixer, volCtrl, vVolume); 
        			GetVolumeControl(mixer, 
        				MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,type,out volCtrl, out 
        				currentVol); 
        			if(vVolume != currentVol) 
        			{ 
        				throw new Exception("Cannot Set Volume"); 
        			} 
        			mixerClose(mixer); 
        		} 
        	} 
        }
        EWF, HORM, MinLogon on XP.

        Zotac ION Atom N330, 2GB low-profile RAM, M3-ATX
        Win Embedded Std 2011 RC
        OCZ Vertex Turbo 30GB SSD
        Lilliput 629 Transflective, WRX Screen Mount
        BlueSoleil BT, i-Blue GM-2 GPS, DirectedHD Radio, Andrea Mic
        VoomPC 2

        Comment


        • #5
          Here is a neat site that translates c# into VB. Its not 100% but its makes it a lot easier... http://authors.aspalliance.com/aldot...translate.aspx

          Comment


          • #6
            .

            This is great I was just going to ask the same damn question... I was actually think about using directX 8.0 for mixer controls..
            Progress [I will seriously never be done!]
            Via EPIA MII
            512MB RAM
            OEM GPS (embedded)
            nLite WinXP pro on
            1GB Extreme III CF card
            Carnetix 1260 startup/ DC-DC regulator
            Software: Still, re-Writing my existing front end in .Net

            Comment


            • #7
              bah

              This definalty is tough to impliment into VB.net
              Progress [I will seriously never be done!]
              Via EPIA MII
              512MB RAM
              OEM GPS (embedded)
              nLite WinXP pro on
              1GB Extreme III CF card
              Carnetix 1260 startup/ DC-DC regulator
              Software: Still, re-Writing my existing front end in .Net

              Comment


              • #8
                I used that C#->VB.NET translator, but had to make a few corrections:

                Code:
                Imports System
                Imports System.Runtime.InteropServices
                
                Public Class AudioMixerHelper
                    Public Const MMSYSERR_NOERROR As Integer = 0
                    Public Const MAXPNAMELEN As Integer = 32
                    Public Const MIXER_LONG_NAME_CHARS As Integer = 64
                    Public Const MIXER_SHORT_NAME_CHARS As Integer = 16
                    Public Const MIXER_GETLINEINFOF_COMPONENTTYPE As Integer = &H3
                    Public Const MIXER_GETCONTROLDETAILSF_VALUE As Integer = &H0
                    Public Const MIXER_GETLINECONTROLSF_ONEBYTYPE As Integer = &H2
                    Public Const MIXER_SETCONTROLDETAILSF_VALUE As Integer = &H0
                    Public Const MIXERLINE_COMPONENTTYPE_DST_FIRST As Integer = &H0
                    Public Const MIXERLINE_COMPONENTTYPE_SRC_FIRST As Integer = &H1000
                    Public Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS As Integer = MIXERLINE_COMPONENTTYPE_DST_FIRST + 4
                    Public Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE As Integer = MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3
                    Public Const MIXERLINE_COMPONENTTYPE_SRC_LINE As Integer = MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2
                    Public Const MIXERCONTROL_CT_CLASS_FADER As Integer = &H50000000
                    Public Const MIXERCONTROL_CT_UNITS_UNSIGNED As Integer = &H30000
                    Public Const MIXERCONTROL_CONTROLTYPE_FADER As Integer = MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED
                    Public Const MIXERCONTROL_CONTROLTYPE_VOLUME As Integer = MIXERCONTROL_CONTROLTYPE_FADER + 1
                
                    Private Declare Ansi Function mixerClose Lib "winmm.dll" (ByVal hmx As Integer) As Integer
                
                    Private Declare Ansi Function mixerGetControlDetailsA Lib "winmm.dll" (ByVal hmxobj As Integer, ByRef pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer
                
                    Private Declare Ansi Function mixerGetDevCapsA Lib "winmm.dll" (ByVal uMxId As Integer, ByVal pmxcaps As MIXERCAPS, ByVal cbmxcaps As Integer) As Integer
                
                    Private Declare Ansi Function mixerGetID Lib "winmm.dll" (ByVal hmxobj As Integer, ByVal pumxID As Integer, ByVal fdwId As Integer) As Integer
                
                    Private Declare Ansi Function mixerGetLineControlsA Lib "winmm.dll" (ByVal hmxobj As Integer, ByRef pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Integer) As Integer
                
                    Private Declare Ansi Function mixerGetLineInfoA Lib "winmm.dll" (ByVal hmxobj As Integer, ByRef pmxl As MIXERLINE, ByVal fdwInfo As Integer) As Integer
                
                    Private Declare Ansi Function mixerGetNumDevs Lib "winmm.dll" () As Integer
                
                    Private Declare Ansi Function mixerMessage Lib "winmm.dll" (ByVal hmx As Integer, ByVal uMsg As Integer, ByVal dwParam1 As Integer, ByVal dwParam2 As Integer) As Integer
                
                    Private Declare Ansi 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 Ansi Function mixerSetControlDetails Lib "winmm.dll" (ByVal hmxobj As Integer, ByRef pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer
                
                    Public Structure MIXERCAPS
                        Public wMid As Integer
                        Public wPid As Integer
                        Public vDriverVersion As Integer
                        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> Public szPname As String
                        Public fdwSupport As Integer
                        Public cDestinations As Integer
                    End Structure 'MIXERCAPS
                       _
                
                    Public Structure MIXERCONTROL
                        Public cbStruct As Integer
                        Public dwControlID As Integer
                        Public dwControlType As Integer
                        Public fdwControl As Integer
                        Public cMultipleItems As Integer
                        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String
                        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String
                        Public lMinimum As Integer
                        Public lMaximum As Integer
                        <MarshalAs(UnmanagedType.U4, SizeConst:=10)> Public reserved As Integer
                    End Structure 'MIXERCONTROL
                       _
                
                    Public Structure MIXERCONTROLDETAILS
                        Public cbStruct As Integer
                        Public dwControlID As Integer
                        Public cChannels As Integer
                        Public item As Integer
                        Public cbDetails As Integer
                        Public paDetails As IntPtr
                    End Structure 'MIXERCONTROLDETAILS
                       _
                
                    Public Structure MIXERCONTROLDETAILS_UNSIGNED
                        Public dwValue As Integer
                    End Structure 'MIXERCONTROLDETAILS_UNSIGNED
                       _
                
                    Public Structure MIXERLINE
                        Public cbStruct As Integer
                        Public dwDestination As Integer
                        Public dwSource As Integer
                        Public dwLineID As Integer
                        Public fdwLine As Integer
                        Public dwUser As Integer
                        Public dwComponentType As Integer
                        Public cChannels As Integer
                        Public cConnections As Integer
                        Public cControls As Integer
                        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String
                        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String
                        Public dwType As Integer
                        Public dwDeviceID As Integer
                        Public wMid As Integer
                        Public wPid As Integer
                        Public vDriverVersion As Integer
                        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> Public szPname As String
                    End Structure 'MIXERLINE
                       _
                
                    Public Structure MIXERLINECONTROLS
                        Public cbStruct As Integer
                        Public dwLineID As Integer
                
                        Public dwControl As Integer
                        Public cControls As Integer
                        Public cbmxctrl As Integer
                        Public pamxctrl As IntPtr
                    End Structure 'MIXERLINECONTROLS
                
                
                    Private Shared Function GetVolumeControl(ByVal hmixer As Integer, ByVal componentType As Integer, ByVal ctrlType As Integer, ByRef mxc As MIXERCONTROL, ByRef vCurrentVol As Integer) As Boolean
                        ' This function attempts to obtain a mixer control. 
                        ' Returns True if successful. 
                        Dim mxlc As New MIXERLINECONTROLS
                        Dim mxl As New MIXERLINE
                        Dim pmxcd As New MIXERCONTROLDETAILS
                        Dim du As New MIXERCONTROLDETAILS_UNSIGNED
                        mxc = New MIXERCONTROL
                        Dim rc As Integer
                        Dim retValue As Boolean
                        vCurrentVol = -1
                
                        mxl.cbStruct = Marshal.SizeOf(mxl)
                        mxl.dwComponentType = componentType
                
                        rc = mixerGetLineInfoA(hmixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)
                
                        If MMSYSERR_NOERROR = rc Then
                            Dim sizeofMIXERCONTROL As Integer = 152
                            Dim ctrl As Integer = Marshal.SizeOf(GetType(MIXERCONTROL))
                            mxlc.pamxctrl = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL)
                            mxlc.cbStruct = Marshal.SizeOf(mxlc)
                            mxlc.dwLineID = mxl.dwLineID
                            mxlc.dwControl = ctrlType
                            mxlc.cControls = 1
                            mxlc.cbmxctrl = sizeofMIXERCONTROL
                
                            ' Allocate a buffer for the control 
                            mxc.cbStruct = sizeofMIXERCONTROL
                
                            ' Get the control 
                            rc = mixerGetLineControlsA(hmixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
                
                            If MMSYSERR_NOERROR = rc Then
                                retValue = True
                
                                ' Copy the control into the destination structure 
                                mxc = CType(Marshal.PtrToStructure(mxlc.pamxctrl, GetType(MIXERCONTROL)), MIXERCONTROL)
                            Else
                                retValue = False
                            End If
                            Dim sizeofMIXERCONTROLDETAILS As Integer = Marshal.SizeOf(GetType(MIXERCONTROLDETAILS))
                            Dim sizeofMIXERCONTROLDETAILS_UNSIGNED As Integer = Marshal.SizeOf(GetType(MIXERCONTROLDETAILS_UNSIGNED))
                            pmxcd.cbStruct = sizeofMIXERCONTROLDETAILS
                            pmxcd.dwControlID = mxc.dwControlID
                            pmxcd.paDetails = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED)
                            pmxcd.cChannels = 1
                            pmxcd.item = 0
                            pmxcd.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED
                
                            rc = mixerGetControlDetailsA(hmixer, pmxcd, MIXER_GETCONTROLDETAILSF_VALUE)
                
                            du = Marshal.PtrToStructure(pmxcd.paDetails, GetType(MIXERCONTROLDETAILS_UNSIGNED))
                
                            vCurrentVol = du.dwValue
                
                            Return retValue
                        End If
                
                        retValue = False
                        Return retValue
                    End Function 'GetVolumeControl
                
                
                    Private Shared Function SetVolumeControl(ByVal hmixer As Integer, ByVal mxc As MIXERCONTROL, ByVal volume As Integer) As Boolean
                        ' This function sets the value for a volume control. 
                        ' Returns True if successful 
                        Dim retValue As Boolean
                        Dim rc As Integer
                        Dim mxcd As New MIXERCONTROLDETAILS
                        Dim vol As New MIXERCONTROLDETAILS_UNSIGNED
                
                        mxcd.item = 0
                        mxcd.dwControlID = mxc.dwControlID
                        mxcd.cbStruct = Marshal.SizeOf(mxcd)
                        mxcd.cbDetails = Marshal.SizeOf(vol)
                
                        ' Allocate a buffer for the control value buffer 
                        mxcd.cChannels = 1
                        vol.dwValue = volume
                
                        ' Copy the data into the control value buffer 
                        mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(GetType(MIXERCONTROLDETAILS_UNSIGNED)))
                        Marshal.StructureToPtr(vol, mxcd.paDetails, False)
                
                        ' Set the control value 
                        rc = mixerSetControlDetails(hmixer, mxcd, MIXER_SETCONTROLDETAILSF_VALUE)
                
                        If MMSYSERR_NOERROR = rc Then
                            retValue = True
                        Else
                            retValue = False
                        End If
                        Return retValue
                    End Function 'SetVolumeControl
                EWF, HORM, MinLogon on XP.

                Zotac ION Atom N330, 2GB low-profile RAM, M3-ATX
                Win Embedded Std 2011 RC
                OCZ Vertex Turbo 30GB SSD
                Lilliput 629 Transflective, WRX Screen Mount
                BlueSoleil BT, i-Blue GM-2 GPS, DirectedHD Radio, Andrea Mic
                VoomPC 2

                Comment


                • #9
                  continued because forums complained text was too long...

                  Code:
                      Public Shared Function GetVolume() As Integer
                          Dim mixer As Integer
                          Dim volCtrl As New MIXERCONTROL
                          Dim currentVol As Integer
                          mixerOpen(mixer, 0, 0, 0, 0)
                          Dim type As Integer = MIXERCONTROL_CONTROLTYPE_VOLUME
                          GetVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, volCtrl, currentVol)
                          mixerClose(mixer)
                  
                          Return currentVol
                      End Function 'GetVolume
                  
                  
                      Public Shared Sub SetVolume(ByVal vVolume As Integer)
                          Dim mixer As Integer
                          Dim volCtrl As New MIXERCONTROL
                          Dim currentVol As Integer
                          mixerOpen(mixer, 0, 0, 0, 0)
                          Dim type As Integer = MIXERCONTROL_CONTROLTYPE_VOLUME
                          GetVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, volCtrl, currentVol)
                          If vVolume > volCtrl.lMaximum Then
                              vVolume = volCtrl.lMaximum
                          End If
                          If vVolume < volCtrl.lMinimum Then
                              vVolume = volCtrl.lMinimum
                          End If
                          SetVolumeControl(mixer, volCtrl, vVolume)
                          GetVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, volCtrl, currentVol)
                          If vVolume <> currentVol Then
                              Throw New Exception("Cannot Set Volume")
                          End If
                          mixerClose(mixer)
                      End Sub 'SetVolume
                  End Class 'AudioMixerHelper
                  EWF, HORM, MinLogon on XP.

                  Zotac ION Atom N330, 2GB low-profile RAM, M3-ATX
                  Win Embedded Std 2011 RC
                  OCZ Vertex Turbo 30GB SSD
                  Lilliput 629 Transflective, WRX Screen Mount
                  BlueSoleil BT, i-Blue GM-2 GPS, DirectedHD Radio, Andrea Mic
                  VoomPC 2

                  Comment


                  • #10
                    Sorry, but me English is not very good....

                    I want to make a program to set the balance control to center always. Could I have it with this code?

                    Somebody has compiled it?
                    Thank you.

                    Greetings....

                    Comment


                    • #11
                      Test it
                      http://img43.exs.cx/img43/2928/lookbalance3pi.jpg
                      Rename to .zip
                      This program block the balance control of wave. This is a good solution to Mapsonic bug.

                      Comment


                      • #12
                        i had no chance to test it yet but i will try tonight! thanx for all the info / translation/ corrections!
                        i will let you know if it works tonight
                        -VIA EPIA M10000/512MB/40GB HD
                        -DWW motorized 7'
                        -BU 303 GPS w/iGuidance/ CF
                        -Opus90w
                        -Belkin Bluetooth
                        -Pioneer HU

                        [||||||||||] 95% done

                        Comment


                        • #13
                          Originally posted by SFiorito
                          continued because forums complained text was too long...
                          Help me please...

                          I try to test this script but I give the next message

                          'An unhandled exception of type 'System.Security.SecurityException' occurred in WindowsApplication6.exe

                          Additional information: System.Security.Permissions.SecurityPermission'
                          when I execute this.

                          In the form load I have this
                          Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                          SetVolume(100)
                          End Sub

                          What is the problem? How I use this sript to control the mixer?


                          Sorry for my enlgish!

                          Bye for now

                          Comment


                          • #14
                            where are you running the application from? is it on the local drive or on a network share?
                            EWF, HORM, MinLogon on XP.

                            Zotac ION Atom N330, 2GB low-profile RAM, M3-ATX
                            Win Embedded Std 2011 RC
                            OCZ Vertex Turbo 30GB SSD
                            Lilliput 629 Transflective, WRX Screen Mount
                            BlueSoleil BT, i-Blue GM-2 GPS, DirectedHD Radio, Andrea Mic
                            VoomPC 2

                            Comment


                            • #15
                              In local drive. This massage is launched when He touch the "winmm.dll" library

                              Comment

                              Working...
                              X