Hello!
I'd like to get a default audio device id through WinAPI with C#. I wish to save this ID (and volume also) for restoring it in the future in WinServer2012 and Windows8. As I googled it is possible with the following WinAPI function:
[DllImport("winmm.dll")]
static extern uint waveOutMessage(IntPtr deviceID, uint uMsg, ref uint dwParam1, ref uint dwParam2);
But I don't have any results with this function on WinServer2012. Did I code something wrong or this is impossible in my case?
Thank you.
What I have tried:
I've found an example to call following functions:
[DllImport("winmm.dll")]
static extern uint waveOutMessage(IntPtr deviceID, uint uMsg, IntPtr dwParam1, IntPtr dwParam2);
or
[DllImport("winmm.dll")]
static extern uint waveOutMessage(IntPtr deviceID, uint uMsg, ref uint dwParam1, ref uint dwParam2);
with a C# method:
string GetAudioOutput()
{
uint originalDeviceId = 0;
uint newDeviceId = 0;
uint DRVM_MAPPER_PREFERRED_GET = 0x2015;
uint DRVM_MAPPER_PREFERRED_SET = 0x2016;
int deviceId = 0;
IntPtr WAVE_MAPPER = new IntPtr(-1);
uint ret = waveOutMessage(WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, GCHandle.Alloc(originalDeviceId, GCHandleType.Pinned).AddrOfPinnedObject() , GCHandle.Alloc(newDeviceId, GCHandleType.Pinned).AddrOfPinnedObject() );
return deviceId.ToString() + originalDeviceId.ToString() + newDeviceId.ToString() + ret.ToString();
}