[wdmaudiodev] Re: obtaining a mixer for a given device interface

  • From: "Jerry Evans" <jerry@xxxxxxxxxx>
  • To: <wdmaudiodev@xxxxxxxxxxxxx>
  • Date: Thu, 6 Oct 2005 15:23:58 +0100

obtaining a mixer for a given device interfaceHi Jeff.

Thanks. I wanted to match a mixer ID to a device GUID. I had another look at 
this and came up with the following:

// On my system mixer index 0 is mapped to a Creative Audigy 2. This has a KS 
device ID of
// 
\\?\pci#ven_1102&dev_0004&subsys_10051102&rev_04#4&1a671d0c&0&08f0#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\wavepci
//
// snippet to get a KS device ID string from a mixer device index
// 0 << mixerIndex << mixerGetNumDevs();
int mixerIndex = 0;
DWORD dwSize = 0;
// how large a buffer do we need ?
DWORD dwError = mixerMessage((HMIXER)mixerIndex,
                        DRV_QUERYDEVICEINTERFACESIZE,
                        (DWORD_PTR)&dwSize,
                        0);
// error check here
// i seemed to be getting MMSYSERR_MOREDATA when using reported size directly 
(!)
dwSize = (dwSize*2)+1;
// buffer to get UNICODE string
std::vector<WCHAR> vec(dwSize,0);
// make the call
dwError = mixerMessage((HMIXER)mixerIndex,
                DRV_QUERYDEVICEINTERFACE,
                (DWORD_PTR)&vec[0],
                dwSize);
// error check here
// length of UID as UNICODE string
DWORD dwLen = wcslen(&vec[0]);
// prepare for conversion to ASCII
std::string uid(dwLen,0);
// convert directly into std::string
WideCharToMultiByte(CP_ACP,0,&vec[0],dwLen,&key[0],dwLen,NULL,NULL);

Other related posts: