#define MMSYSERR_BASE          0
#define MMSYSERR_INVALPARAM   (MMSYSERR_BASE + 11) /* invalid parameter passed */using System;
using System.Runtime.InteropServices;class GetVolume
{
[DllImport("winmm.dll")] 
public  static  extern  uint waveOutGetVolume(IntPtr deviceID,  out uint Volume);
  public static void Main()
  {
uint v;
IntPtr p = new IntPtr(0);
uint i = waveOutGetVolume(p, out v);
if (i == 0)
{
uint vleft = v & 0xFFFF;
uint vright = (v & 0xFFFF0000) >> 16;
Console.WriteLine("left:{0}, right:{0}", vleft, vright);
}
else
{
Console.WriteLine(v);
Console.WriteLine(i);
}
  }
}

解决方案 »

  1.   

    the first two lines show what error code 11 means, do not use it in C# code when compiling
      

  2.   

    多谢,试过通过,但还有点疑问,为什么用waveOutGetVolume函数得到的值,不是控制面板中的音量的值呢?也就是说,控制面板中音量的改变,并不影响waveOutGetVolume函数得到的值,为什么这样,难道它们是不同的设备吗?
      

  3.   


     win form 类做得很强大
     但有个最大的缺陷,就是多媒体支持太差
      

  4.   

    可能微软的想法是,也不用再费事做多媒体类库了,大家都用DirectX9就行了。
      

  5.   

    from MSDN documentation:
    "...Not all devices support volume changes. To determine whether the device supports volume control, use the WAVECAPS_VOLUME flag to test the dwSupport member of the WAVEOUTCAPS structure (filled by the waveOutGetDevCaps function).
    ..."
      

  6.   

    it works for me, if you open the Volume Control and change the Wave Volume, and run the above code, the values changesuse waveOutGetNumDevs() to get the number of devices on your machine