SafeDispatch/Safedispatch_4_0/AudioDeviceName.cs
2024-02-22 18:43:59 +02:00

115 lines
3.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Collections;
using SafeMobileLib;
namespace Safedispatch_4_0
{
class AudioDeviceName
{
private const int MAXPNAMELEN = 122;
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct WaveInCaps
{
public short wMid;
public short wPid;
public int vDriverVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXPNAMELEN)]
public string szPname;
public int dwFormats;
public short wChannels;
public short wReserved1;
}
[DllImport("winmm.dll")]
public static extern int waveInGetNumDevs();
[DllImport("winmm.dll")]
public static extern int waveOutGetNumDevs();
[DllImport("winmm.dll", EntryPoint = "waveInGetDevCaps")]
public static extern int waveInGetDevCapsA(int uDeviceID, ref WaveInCaps lpCaps, int uSize);
[DllImport("winmm.dll", EntryPoint = "waveOutGetDevCaps")]
public static extern int waveOutGetDevCapsA(int uDeviceID, ref WaveInCaps lpCaps, int uSize);
ArrayList arrLst = new ArrayList();
public int Count
{
get {return arrLst.Count;}
}
public string this[int indexer]
{
get{return (string)arrLst[indexer];}
}
public AudioDeviceName()
{
}
private String trimHi(String s)
{
int index = s.IndexOf("(Hi");
if (index >= 0)
{
return s.Substring(0, index);
}
else
{
return s;
}
}
public ArrayList getInDevices()
{
ArrayList arrLst = new ArrayList();
try
{
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(trimHi(waveInCaps.szPname));
}
}
}
catch (Exception ex)
{
SM.Debug("getInDevices:"+ex.ToString());
}
return arrLst;
}
public ArrayList getOutDevices()
{
ArrayList arrLst = new ArrayList();
try
{
int waveOutDevicesCount = waveOutGetNumDevs();
if (waveOutDevicesCount > 0)
{
for (int uDeviceID = 0; uDeviceID < waveOutDevicesCount; uDeviceID++)
{
WaveInCaps waveInCaps = new WaveInCaps();
waveOutGetDevCapsA(uDeviceID, ref waveInCaps, Marshal.SizeOf(typeof(WaveInCaps)));
arrLst.Add(trimHi(waveInCaps.szPname));
}
}
}
catch (Exception ex)
{
SM.Debug("getOutDevices:" + ex.ToString());
}
return arrLst;
}
}
}