Could anyone please help me out in retrieving the number of audio devices using
"waveInGetNumDevs" ?
I cannot make out how to do it ?
Thanx
:)

Here is the code ...

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Collections;

namespace clsRec
{
    class clsRecDevices
    {      
        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        public struct WaveInCaps
        {
            public short wMid;
            public short wPid;
            public int vDriverVersion;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
            public char[] szPname;
            public uint dwFormats;
            public short wChannels;
            public short wReserved1;
        }      

        [DllImport("winmm.dll")]
        public static extern int waveInGetNumDevs();

        [DllImport("winmm.dll", EntryPoint = "waveInGetDevCaps")]
        public static extern int waveInGetDevCapsA(int uDeviceID, ref WaveInCaps lpCaps, int uSize);

        ArrayList arrLst = new ArrayList();

        int position = -1;

        public int Count
        {            
            get {return arrLst.Count;}
        }

        public string this[int indexer]
        {
            get{return (string)arrLst[indexer];}
        }

        public clsRecDevices()
        {
            int waveInDevicesCount = waveInGetNumDevs();
            if (waveInDevicesCount > 0)
            {
                for (int uDeviceID = 0; uDeviceID < waveInDevicesCount; uDeviceID++)
                {
                    WaveInCaps waveInCaps = new WaveInCaps();
                    waveInGetDevCapsA(uDeviceID,ref waveInCaps,Marshal.SizeOf(typeof(WaveInCaps)));
                    arrLst.Add(new string(waveInCaps.szPname).Remove(new string(waveInCaps.szPname).IndexOf('\0')).Trim());                    
                }
            }
        }        
    }
}

Now if I wish to print the result on an form ..... !
They say I should use

clsRecDevices recDev = new clsRecDevices();
for (int i = 0; i < recDev.Count; i++){
    MessageBox.Show(recDev[i]);
}

and when I tried to create a form .... I was having difficulties ....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Text;
using System.Data;
using System.Drawing;

namespace clsRec
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
            
            clsRec.clsRecDevices recDev = new clsRecDevices();
            for (int i = 0; i < recDev.Count; i++)
            {
                MessageBox.Show(recDev[i]);
            }   
        }
    }
}

Please also tell me how to connect two different CS programs ..... I was having difficulty in naming the correct Namespaces !

Yes ... I want the form to be displayed when I run the first code (on the top).
But I am facing difficulties in making the form.
That form should print the device properties and ID.
I have never made a form before ... :(

This article has been dead for over six months. Start a new discussion instead.