获取默认的音频设备属性getDefaultDevice
2022-09-29
110
0
使用COREAPI获取默认音频属性
wstring DeviceAPOInfo::getDefaultDevice(bool input, int role)
{
wstring result;
IMMDeviceEnumerator* enumerator = NULL;
HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&enumerator);
if (SUCCEEDED(hr))
{
IMMDevice* endPoint = NULL;
hr = enumerator->GetDefaultAudioEndpoint(input ? eCapture : eRender, (ERole)role, &endPoint);
if (SUCCEEDED(hr))
{
IPropertyStore* propertyStore = NULL;
hr = endPoint->OpenPropertyStore(STGM_READ, &propertyStore);
if (SUCCEEDED(hr))
{
PROPVARIANT variant;
PropVariantInit(&variant);
hr = propertyStore->GetValue(guidPropertyKey, &variant);
if (SUCCEEDED(hr))
{
result = variant.pwszVal;
PropVariantClear(&variant);
}
propertyStore->Release();
}
endPoint->Release();
}
enumerator->Release();
}
return result;
}