Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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; //4
            uint newDeviceId = 0; //4
            uint DRVM_MAPPER_PREFERRED_GET = 0x2015;
            uint DRVM_MAPPER_PREFERRED_SET = 0x2016;
            int deviceId = 0; //-1

            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() );
            //uint ret = waveOutMessage(WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, ref originalDeviceId, ref newDeviceId);
            return deviceId.ToString() + originalDeviceId.ToString() + newDeviceId.ToString() + ret.ToString(); //I get 0000
        }
Posted

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