I've been trying to get the current system volume using C# / Windows API. I'm on Windows 8.1 though I would like the solution to also work on Windows 7.
This:
[DllImport("winmm.dll")]
public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
does not work, with the system volume after Windows XP.
I have tried this:
[DllImport("Audioses.dll", EntryPoint = "GetMasterVolume", SetLastError = true)]
static extern int GetMasterVolume(out float pfLevelDB);
public void getVolume()
{
float f = 0.0F;
int i = GetMasterVolume(out f);
MessageBox.Show(f.ToString());
}
However the application never gets to the MessageBox.Show(...), though running line-by-line shows that it gets to GetMasterVolume(out f) then fails. I think something must be wrong with my declaration or usage.
Output shows: System.EntryPointNotFoundException
GetMasterVolumeLevel: http://msdn.microsoft.com/en-us/library/windows/desktop/dd316533(v=vs.85).aspx