问题
As I just found out the hard way, friendly names are not guaranteed to be unique. Bonus points if I can instantiate the filter from that identifier without having to enumerate them.
回答1:
Renderer filters wrapping WaveOut devices can be identified by WaveOutId. Those wrapping DirectSound devices can be identified by DSGuid.
ICreateDevEnum* devices;
if (CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (LPVOID*)&devices) == S_OK)
{
IEnumMoniker* enumerator;
if (devices->CreateClassEnumerator(CLSID_AudioRendererCategory, &enumerator, 0) == S_OK)
{
IMoniker* moniker;
while (enumerator->Next(1, &moniker, NULL) == S_OK)
{
IPropertyBag* properties;
if (moniker->BindToStorage(NULL, NULL, IID_IPropertyBag, (void**)&properties) == S_OK)
{
VARIANT variant;
VariantInit(&variant);
if (properties->Read(L"WaveOutId", &variant, NULL) == S_OK)
{
// variant.lVal now contains the id of the wrapped WaveOut device.
}
else if (properties->Read(L"DSGuid", &variant, NULL) == S_OK)
{
// variant.bstrVal now contains an uppercase GUID.
// It's the same GUID you would get from DirectSoundEnumerate.
}
VariantClear(&variant);
properties->Release();
}
moniker->Release();
}
enumerator->Release();
}
devices->Release();
}
来源:https://stackoverflow.com/questions/6545539/how-do-i-identify-directshow-audio-renderer-filters-uniquely