我正在维护一个旧代码库,它使用waveOutGetDevCaps来获取系统上音频设备的名称。在Windows 7计算机上,这会导致名称被截断,因为WAVEOUTCAPS.szPname受MAXPNAMELEN(31个字符)的限制。
Win7的做法是什么?
答案 0 :(得分:0)
您可以使用其中一个Core Audio API:
// get the device enumerator
IMMDeviceEnumerator* pEnumerator = NULL;
HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL,
CLSCTX_ALL,__uuidof(IMMDeviceEnumerator),
(void**)&pEnumerator);
// get the endpoint collection
IMMDeviceCollection* pCollection = NULL;
DWORD mask = DEVICE_STATE_ACTIVE || DEVICE_STATE_UNPLUGGED;
hr = pEnumerator->EnumAudioEndpoints(eRender, mask, &pCollection);
// get the size of the collection
UINT count = 0;
hr = pCollection->GetCount(&count);
for (int i = 0; i < (int)count; i++)
{
// get the endpoint
IMMDevice* pEndPoint = NULL;
hr = pCollection->Item(i, &pEndPoint);
// get the human readable name
String^ friendlyName;
IPropertyStore* pProps = NULL;
HRESULT hr = pEndPoint->OpenPropertyStore(STGM_READ, &pProps);
PROPVARIANT varName;
PropVariantInit(&varName);
hr = pProps->GetValue(PKEY_Device_FriendlyName, &varName);
friendlyName = gcnew String(varName.pwszVal);
PropVariantClear(&varName);
}
在上面的代码中删除了错误处理,使其更具可读性。 (我喜欢使用C ++ / CLI在C#和Windows API之间移动。)
现在更难的部分是将端点名称与旧代码库中的MME设备相关联。
答案 1 :(得分:0)
我发现了使用注册表查找音频设备的全名(输入和输出)的另一种方法。
在Windows 7和Windows 10上工作。
1. drop USER 'user_name'@'localhost';
flush privileges;
CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'user_name';
GRANT ALL PRIVILEGES ON * . * TO 'user_name'@'localhost';
ALTER USER 'user_name'@'localhost' IDENTIFIED WITH mysql_native_password BY
'user_name';
2. drop USER 'user_name'@'localhost';
flush privileges;
CREATE USER 'user_name'@'localhost' IDENTIFIED WITH mysql_native_password BY 'user_name';
GRANT ALL PRIVILEGES ON * . * TO 'user_name'@'localhost'
3. If the user is already created, the use the following command:
ALTER USER 'user_name'@'localhost' IDENTIFIED WITH mysql_native_password BY
'user_name';