开发者

Detecting Audio Input & output devices connected to system

I w开发者_JAVA百科ant to findout how many audio input and output devices connected to my system in C#.net

Please suggest any.

Thanks.


You need to access the necessary Windows API functions.

This class should get you started - Win32.GetSoundDevices returns a list of device names. Look up WAVEOUTCAPS in the Windows SDK for details of the other information you can get.

public class Win32 {
    [DllImport("winmm.dll", SetLastError=true)]
    static extern uint waveOutGetNumDevs();

    [DllImport("winmm.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern uint waveOutGetDevCaps(uint hwo,ref WAVEOUTCAPS pwoc,uint cbwoc);

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct WAVEOUTCAPS {
        public ushort wMid;
        public ushort wPid;
        public uint vDriverVersion;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
        public string szPname;
        public uint dwFormats;
        public ushort wChannels;
        public ushort wReserved1;
        public uint dwSupport;
    }

    public static string [] GetSoundDevices() {
        uint devices = waveOutGetNumDevs();
        string [] result = new string[devices];
        WAVEOUTCAPS caps = new WAVEOUTCAPS();

        for(uint i = 0; i < devices; i++) {
            waveOutGetDevCaps(i, ref caps, (uint)Marshal.SizeOf(caps));
            result[i] = caps.szPname;
        }
        return result;
    }


}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜