Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a small piece of code that I used to change the wave volume of on windows XP. I used

C#
[DllImport("winmm.dll")]
public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);

[DllImport("winmm.dll")]
public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);


When I use this code on windwos 7. and change volume

C#
int NewVolume = ((ushort.MaxValue / 10) * currentVolume);
// Set the same volume for both the left and the right channels
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
// Set the volume
                waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);


The volume is not getting changed. When i opened the master volume window of win7 I could see the volume level bar getting changed but the volume change was not happening.

I know there are other ways to do the same thing on windows 7 but I was just wondering why the volume is not changing if my function call is able to set the volume bar to the required level?
Posted

Hi,

since Windows Vista/7 MS changed the access to control volume, mixers, etc. and it's called the coreaudio API.
Here are some links, I'm sure you can work something out with it:

http://msdn.microsoft.com/en-us/library/ms678715.aspx?ppud=4[^]
Vista Core Audio API Master Volume Control[^]
http://rongchaua.net/blog/c-adjust-master-volume-in-vista-and-windows-7/[^]

You can also use or have a look at NAudio Wrapper:
http://naudio.codeplex.com/[^]

Good Luck ;)
Regards
 
Share this answer
 
v2
I made the experience that the waveOutSetVolume and waveOutGetVolume Functions only change the volume ouput of your current application and not the master system volume. therefore the volume is raised or lowered but you dont see any change on the master volume scrollbar. open the mixer and take a look there.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900