Click here to Skip to main content
14,737,119 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Can anybody guide how can I detect audio jack plugged in and out?
Updated 17-Sep-15 23:20pm

1 solution

Google says:[^]

Try one of the first hits:

    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;


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