From: Rich Milburn [MVP] on
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 :op 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 -----------------------------------------------


From: The Grim Reaper on
I managed to write a class to control Wave, Master, CD player, Line In and
Microphone volumes in the windows mixer many years ago.
It was in VB6, and took me several months of research to build it all! I
upgraded it to VB2003 a few years ago, but I don't think I ever got it
working like it used to.
This article is the most useful one I've found so far - it's C#, but I find
that easier to translate to VB.NET than VB6 sometimes!
http://www.codeproject.com/useritems/AudioLib.asp

As for your code below, here's a few pointers;
a) Change your As Short declarations to As Integer (a Long in VB6 translates
to a Short in .NET, you want an Integer (32 bits))
b) Dim 'tmp' as a string, and 'a' as integer, not objects. That clears off
the first 3 upgrade warnings.
c) Switch Option Strict On - it's there to help - not just fill up the task
list/error list!!

This is the MSDN entry for WaveOutSetVolume. I'm suprised you couldn't find
it in your local MSDN(??).
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_waveoutsetvolume.asp
Start there, and go through each of the "See Also" items to get your head
round how the API call works.

This post sets the WaveOutVolume to 0. Note the different API declaration
to your "old" method.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=178167&SiteId=1

Hope that gets you started.
_____________________________________________________
The Grim Reaper

"Rich Milburn [MVP]" <richdotmilburnatapplebeesdotcom> wrote in message
news:eZ2D$pcLGHA.1180(a)TK2MSFTNGP09.phx.gbl...
> 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 :op 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 -----------------------------------------------
>
>


From: Cor Ligthert [MVP] on
Rich,

I am not a sound guy or whatever multimedia, however I would ask it as well
in one of the newsgroup

microsoft.public.directX*.

Not to sent you away here of course as some people see this kind of
messages.

Be aware that DirectX is very bad documented to use in combination with
VBNet and bad for C# all is still C++ it is a little bit looking in the past
using that.

I have tried some things with it, and saw things as you are asking for.

Cor


From: Rich Milburn [MVP] on
Thank you very much! I'll get started on that right away! :)

--
Rich Milburn
[MVP - Directory Services]
"The Grim Reaper" <grim_reaper(a)REMOVEbtopenworld.com> wrote in message
news:dsgkbe$mtj$1(a)nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
>I managed to write a class to control Wave, Master, CD player, Line In and
>Microphone volumes in the windows mixer many years ago.
> It was in VB6, and took me several months of research to build it all! I
> upgraded it to VB2003 a few years ago, but I don't think I ever got it
> working like it used to.
> This article is the most useful one I've found so far - it's C#, but I
> find that easier to translate to VB.NET than VB6 sometimes!
> http://www.codeproject.com/useritems/AudioLib.asp
>
> As for your code below, here's a few pointers;
> a) Change your As Short declarations to As Integer (a Long in VB6
> translates to a Short in .NET, you want an Integer (32 bits))
> b) Dim 'tmp' as a string, and 'a' as integer, not objects. That clears
> off the first 3 upgrade warnings.
> c) Switch Option Strict On - it's there to help - not just fill up the
> task list/error list!!
>
> This is the MSDN entry for WaveOutSetVolume. I'm suprised you couldn't
> find it in your local MSDN(??).
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_waveoutsetvolume.asp
> Start there, and go through each of the "See Also" items to get your head
> round how the API call works.
>
> This post sets the WaveOutVolume to 0. Note the different API declaration
> to your "old" method.
> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=178167&SiteId=1
>
> Hope that gets you started.
> _____________________________________________________
> The Grim Reaper
>
> "Rich Milburn [MVP]" <richdotmilburnatapplebeesdotcom> wrote in message
> news:eZ2D$pcLGHA.1180(a)TK2MSFTNGP09.phx.gbl...
>> 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 :op 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 -----------------------------------------------
>>
>>
>
>


From: Rich Milburn [MVP] on
I downloaded the source code you referred to, and tried to wade through
it... it sure does a lot of stuff... I did indeed already find the MSDN link
on waveOutSetVolume, and I have indeed gotten that one working. What I
could not figure out is what is the comparable API for MasterOutSetVolume -
not that it is called that, it's not - if it was, I wouldn't have to ask :)
I did post this to directx.audio also, but that group is pretty slow...

I cut my vb6 code down to:

Private Declare Function waveOutSetVolume Lib "WINMM.DLL" (ByVal wDeviceID
As Integer, ByVal dwVolume As Long) As Integer

Private Sub SetVol_Click()
Dim a 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)
End Sub

any ideas what the master volume set function is called, or how I can find
out? Did you figure that out in VB6?
thanks again -
Rich
--
Rich Milburn
[MVP - Directory Services]

"The Grim Reaper" <grim_reaper(a)REMOVEbtopenworld.com> wrote in message
news:dsgkbe$mtj$1(a)nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
>I managed to write a class to control Wave, Master, CD player, Line In and
>Microphone volumes in the windows mixer many years ago.
> It was in VB6, and took me several months of research to build it all! I
> upgraded it to VB2003 a few years ago, but I don't think I ever got it
> working like it used to.
> This article is the most useful one I've found so far - it's C#, but I
> find that easier to translate to VB.NET than VB6 sometimes!
> http://www.codeproject.com/useritems/AudioLib.asp
>
> As for your code below, here's a few pointers;
> a) Change your As Short declarations to As Integer (a Long in VB6
> translates to a Short in .NET, you want an Integer (32 bits))
> b) Dim 'tmp' as a string, and 'a' as integer, not objects. That clears
> off the first 3 upgrade warnings.
> c) Switch Option Strict On - it's there to help - not just fill up the
> task list/error list!!
>
> This is the MSDN entry for WaveOutSetVolume. I'm suprised you couldn't
> find it in your local MSDN(??).
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_waveoutsetvolume.asp
> Start there, and go through each of the "See Also" items to get your head
> round how the API call works.
>
> This post sets the WaveOutVolume to 0. Note the different API declaration
> to your "old" method.
> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=178167&SiteId=1
>
> Hope that gets you started.
> _____________________________________________________
> The Grim Reaper
>
> "Rich Milburn [MVP]" <richdotmilburnatapplebeesdotcom> wrote in message
> news:eZ2D$pcLGHA.1180(a)TK2MSFTNGP09.phx.gbl...
>> 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 :op 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 -----------------------------------------------
>>
>>
>
>