R
Rich Milburn [MVP]
Ok I am not a programmer, I copied some code and very painfully got it
working in VB6. I can adjust the volume with waveOutSetVolume on winmm.dll.
But I could not seem to be able to figure out how to adjust the master
volume. I thought maybe if I upgraded this into VS2005 VB.Net then it might
be a little easier. But now I am getting PInvokeStackImbalance messages on
this, and it doesn't even run. We're talking a very little program... A
programmer-friend of mine told me this might be related to me calling dlls
instead of using namespaces, he thinks
something.computer.soundcard.volume.set or some such thing. My experience
is vbScript so I am lost - I read you can't do this in vbScript, there are
lots of questions out there about how do you control the master volume, lots
of answers that dodge that question... anyone want to take a stab at fixing
this, or pointing me to a good help-myself point? I do have MSDN Library
but I have not made it through the whole DVD yet
p I'm not sure what to
even search for. I suspect there is something like waveOutSetVolume but not
starting with wave....
Anyway first is the VB.Net conversion (this is all in the form code),
complete with errors, then is the vb6 code that works - type in a percent
and it sets the wave volume.
TIA if anyone wants to take a stab at it...
--
Rich Milburn
[MVP - Directory Services]
'----------------vbNet code-----------------------------
' This gets several errors from the conversion from vb6, most of it is
copied and modified from vb6 (I think) examples
Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class Form1
Inherits System.Windows.Forms.Form
Private Declare Function waveOutSetVolume Lib "WINMM.DLL" (ByVal wDeviceID
As Short, ByVal dwVolume As Integer) As Short
Private Declare Function waveOutGetVolume Lib "WINMM.DLL" (ByVal wDeviceID
As Short, ByRef lpdwVolume As Integer) As Short
Const SND_ASYNC As Short = &H1s
Const SND_NODEFAULT As Short = &H2s
Dim CurrentVolLeft As Integer
Dim CurrentVolRight As Integer
Private Sub SetMaxVol_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles SetMaxVol.Click
Dim x As Short
Dim a As Object
Dim i As Integer
Dim tmp As Object
Dim vol As String
vol = CStr(CDbl(Text1.Text) / 100 * 65535)
'UPGRADE_WARNING: Couldn't resolve default property of object tmp. Click for
more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
tmp = VB.Right(Hex(CDbl(vol) + 65536), 4)
'UPGRADE_WARNING: Couldn't resolve default property of object tmp. Click for
more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
vol = CStr(CInt("&H" & tmp & tmp))
'UPGRADE_WARNING: Couldn't resolve default property of object a. Click for
more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
a = waveOutSetVolume(0, CInt(vol))
' x = waveOutSetVolume(0, &HFFFFFFFF)
End Sub
Private Sub cmdRefresh_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles cmdRefresh.Click
Dim x As Short
Dim BothVolumes As Integer
Dim tmp As String
x = waveOutGetVolume(0, BothVolumes)
CurrentVolLeft = BothVolumes And &HFFFF
CurrentVolRight = (CShort(BothVolumes And &HFFFF0000) / &H10000) And &HFFFF
LeftVol.Text = Hex(CurrentVolLeft)
RightVol.Text = Hex(CurrentVolRight)
tmp = "&h" & VB.Right(Hex(BothVolumes), 4)
Text1.Text = CStr((CInt(tmp) / 65535) * 100)
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs
As System.EventArgs) Handles MyBase.Load
cmdRefresh_Click(cmdRefresh, New System.EventArgs())
End Sub
End Class
'------------------ end vbNet code--------------------------
'vb6 code -----------------------------------------------
'this works for wave volume, but could not figure out master volume
Option Explicit
Private Declare Function waveOutSetVolume Lib "WINMM.DLL" (ByVal wDeviceID
As Integer, ByVal dwVolume As Long) As Integer
Private Declare Function waveOutGetVolume Lib "WINMM.DLL" (ByVal wDeviceID
As Integer, lpdwVolume As Long) As Integer
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Dim CurrentVolLeft As Long
Dim CurrentVolRight As Long
Private Sub SetMaxVol_Click()
Dim x As Integer
Dim a, i As Long
Dim tmp, vol As String
vol = Text1 / 100 * 65535
tmp = Right((Hex$(vol + 65536)), 4)
vol = CLng("&H" & tmp & tmp)
a = waveOutSetVolume(0, vol)
' x = waveOutSetVolume(0, &HFFFFFFFF)
End Sub
Private Sub cmdRefresh_Click()
Dim x As Integer
Dim BothVolumes As Long
Dim tmp As String
x = waveOutGetVolume(0, BothVolumes)
CurrentVolLeft = BothVolumes And &HFFFF&
CurrentVolRight = ((BothVolumes And &HFFFF0000) / &H10000) And &HFFFF&
LeftVol.Caption = Hex$(CurrentVolLeft)
RightVol.Caption = Hex$(CurrentVolRight)
tmp = "&h" & Right(Hex$(BothVolumes), 4)
Text1 = (CLng(tmp) / 65535) * 100
End Sub
Private Sub Form_Load()
cmdRefresh_Click
End Sub
'--------------------- end vb6
code -----------------------------------------------
working in VB6. I can adjust the volume with waveOutSetVolume on winmm.dll.
But I could not seem to be able to figure out how to adjust the master
volume. I thought maybe if I upgraded this into VS2005 VB.Net then it might
be a little easier. But now I am getting PInvokeStackImbalance messages on
this, and it doesn't even run. We're talking a very little program... A
programmer-friend of mine told me this might be related to me calling dlls
instead of using namespaces, he thinks
something.computer.soundcard.volume.set or some such thing. My experience
is vbScript so I am lost - I read you can't do this in vbScript, there are
lots of questions out there about how do you control the master volume, lots
of answers that dodge that question... anyone want to take a stab at fixing
this, or pointing me to a good help-myself point? I do have MSDN Library
but I have not made it through the whole DVD yet

even search for. I suspect there is something like waveOutSetVolume but not
starting with wave....
Anyway first is the VB.Net conversion (this is all in the form code),
complete with errors, then is the vb6 code that works - type in a percent
and it sets the wave volume.
TIA if anyone wants to take a stab at it...
--
Rich Milburn
[MVP - Directory Services]
'----------------vbNet code-----------------------------
' This gets several errors from the conversion from vb6, most of it is
copied and modified from vb6 (I think) examples
Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class Form1
Inherits System.Windows.Forms.Form
Private Declare Function waveOutSetVolume Lib "WINMM.DLL" (ByVal wDeviceID
As Short, ByVal dwVolume As Integer) As Short
Private Declare Function waveOutGetVolume Lib "WINMM.DLL" (ByVal wDeviceID
As Short, ByRef lpdwVolume As Integer) As Short
Const SND_ASYNC As Short = &H1s
Const SND_NODEFAULT As Short = &H2s
Dim CurrentVolLeft As Integer
Dim CurrentVolRight As Integer
Private Sub SetMaxVol_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles SetMaxVol.Click
Dim x As Short
Dim a As Object
Dim i As Integer
Dim tmp As Object
Dim vol As String
vol = CStr(CDbl(Text1.Text) / 100 * 65535)
'UPGRADE_WARNING: Couldn't resolve default property of object tmp. Click for
more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
tmp = VB.Right(Hex(CDbl(vol) + 65536), 4)
'UPGRADE_WARNING: Couldn't resolve default property of object tmp. Click for
more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
vol = CStr(CInt("&H" & tmp & tmp))
'UPGRADE_WARNING: Couldn't resolve default property of object a. Click for
more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
a = waveOutSetVolume(0, CInt(vol))
' x = waveOutSetVolume(0, &HFFFFFFFF)
End Sub
Private Sub cmdRefresh_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles cmdRefresh.Click
Dim x As Short
Dim BothVolumes As Integer
Dim tmp As String
x = waveOutGetVolume(0, BothVolumes)
CurrentVolLeft = BothVolumes And &HFFFF
CurrentVolRight = (CShort(BothVolumes And &HFFFF0000) / &H10000) And &HFFFF
LeftVol.Text = Hex(CurrentVolLeft)
RightVol.Text = Hex(CurrentVolRight)
tmp = "&h" & VB.Right(Hex(BothVolumes), 4)
Text1.Text = CStr((CInt(tmp) / 65535) * 100)
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs
As System.EventArgs) Handles MyBase.Load
cmdRefresh_Click(cmdRefresh, New System.EventArgs())
End Sub
End Class
'------------------ end vbNet code--------------------------
'vb6 code -----------------------------------------------
'this works for wave volume, but could not figure out master volume
Option Explicit
Private Declare Function waveOutSetVolume Lib "WINMM.DLL" (ByVal wDeviceID
As Integer, ByVal dwVolume As Long) As Integer
Private Declare Function waveOutGetVolume Lib "WINMM.DLL" (ByVal wDeviceID
As Integer, lpdwVolume As Long) As Integer
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Dim CurrentVolLeft As Long
Dim CurrentVolRight As Long
Private Sub SetMaxVol_Click()
Dim x As Integer
Dim a, i As Long
Dim tmp, vol As String
vol = Text1 / 100 * 65535
tmp = Right((Hex$(vol + 65536)), 4)
vol = CLng("&H" & tmp & tmp)
a = waveOutSetVolume(0, vol)
' x = waveOutSetVolume(0, &HFFFFFFFF)
End Sub
Private Sub cmdRefresh_Click()
Dim x As Integer
Dim BothVolumes As Long
Dim tmp As String
x = waveOutGetVolume(0, BothVolumes)
CurrentVolLeft = BothVolumes And &HFFFF&
CurrentVolRight = ((BothVolumes And &HFFFF0000) / &H10000) And &HFFFF&
LeftVol.Caption = Hex$(CurrentVolLeft)
RightVol.Caption = Hex$(CurrentVolRight)
tmp = "&h" & Right(Hex$(BothVolumes), 4)
Text1 = (CLng(tmp) / 65535) * 100
End Sub
Private Sub Form_Load()
cmdRefresh_Click
End Sub
'--------------------- end vb6
code -----------------------------------------------