如何从 Win32 中的总线关系获取设备实例路径 API

How to get Device Instance path from Bus Relations in Win32 API

是否有从总线关系(例如:{0.0.1.00000000}。 {4234a4c6-3535-49d6-971c-76ce1f22521e}) ?

我意识到 Windows 中的一些术语有别名,“设备实例路径”和“总线关系”,我指的是在设备管理器中找到的两个属性:

我已尝试从 PropertyStore

获取设备实例路径
int getProperty(std::string& sampleID)
{
   HRESULT hr = S_OK;
   IMMDeviceEnumerator* pEnumerator = NULL;


   //CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

   hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
       NULL,
       CLSCTX_INPROC_SERVER,
       __uuidof(IMMDeviceEnumerator),
       (void**)&pEnumerator);

   if (hr != S_OK)
   {
       // error cleanup
       return hr;
   }

   IMMDevice* pEndpoint = NULL;
   std::wstring wSampleID(sampleID.begin(), sampleID.end());
   hr = pEnumerator->GetDevice(wSampleID.c_str(), &pEndpoint);
   if (hr != S_OK || pEndpoint == NULL)
   {
       // error cleanup
       return hr;
   }

   if (!pEndpoint)
   {
       // error cleanup
       return hr;
   }

   IPropertyStore* pProps = NULL;
   hr = pEndpoint->OpenPropertyStore(
       STGM_READ, &pProps);

   PROPVARIANT varName;
   // Initialize container for property value.
   PropVariantInit(&varName);

   hr = pProps->GetValue(
       PKEY_AudioEndpoint_GUID, &varName);
   if (hr != S_OK)
   {
       //error cleanup
       return hr;
   }
   std::cout << varName.pwszVal << std::endl;

   PropVariantClear(&varName);
   SAFE_RELEASE(pProps)
   SAFE_RELEASE(pEndpoint)
   SAFE_RELEASE(pEnumerator);
   return hr;
}

但似乎没有 属性 键来检索音频端点 IMMDevice 的这条信息。任何建议表示赞赏。

An example would be a headphone + microphone device which yields two Bus Relation strings, one for headphone and the other for microphone. My goal is to group the Bus Relations belonging to the same physical device.

Bus Relations属于同一个物理设备已经分组,可以通过"Bus relations" 属性 同一物理音频设备(父级)。 您可以通过设备管理器(查看 -> 连接设备)找到它,如下所示:

Is there a good way to get the Device Instance path(e.g: USB\VID_021D&PID_0C51&MI_00&192CE49&4&0000) from Bus Relations (e.g:{0.0.1.00000000}.{4234a4c6-3535-49d6-971c-76ce1f22521e}) ?

虽然不清楚您将使用什么分组总线关系。但是您会发现,并非所有 (USB) 设备都具有这种格式的 设备实例路径USB\VID_xxxx&PID_xxxx*。以上面截图中的Microphone为例,其Device Instance路径如下,与其parent的总线关系之一相同。