要获取插孔信息,您需要使用DeviceTopology API.
此API定义了一个IKsJackDescription接口,可为您提供插孔连接器信息.以下是一个示例控制台应用程序,它在所有渲染设备的计算机上显示此信息:
int main() { HRESULT hr = S_OK; CoInitialize(NULL); CComPtrenumerator; hr = enumerator.CoCreateInstance(__uuidof(MMDeviceEnumerator)); if (SUCCEEDED(hr)) { CComPtr devices; hr = enumerator->EnumAudioEndpoints(EDataFlow::eRender, DEVICE_STATEMASK_ALL, &devices); if (SUCCEEDED(hr)) { UINT count = 0; devices->GetCount(&count); for (int i = 0; i < count; i++) { CComPtr device; hr = devices->Item(i, &device); if (SUCCEEDED(hr)) { CComPtr store; hr = device->OpenPropertyStore(STGM_READ, &store); if (SUCCEEDED(hr)) { PROPVARIANT pv; PropVariantInit(&pv); hr = store->GetValue(PKEY_Device_FriendlyName, &pv); if (SUCCEEDED(hr)) { PWSTR p; PSFormatForDisplayAlloc(PKEY_Device_FriendlyName, pv, PDFF_DEFAULT, &p); wprintf(L"name: '%s'\n", p); CoTaskMemFree(p); } PropVariantClear(&pv); } CComPtr topology; hr = device->Activate(__uuidof(IDeviceTopology), CLSCTX_ALL, NULL, (void**)&topology); if (SUCCEEDED(hr)) { CComPtr connector; hr = topology->GetConnector(0, &connector); if (SUCCEEDED(hr)) { CComPtr connectedTo; hr = connector->GetConnectedTo(&connectedTo); if (SUCCEEDED(hr)) { CComPtr part; hr = connectedTo->QueryInterface(&part); if (SUCCEEDED(hr)) { CComPtr jack; hr = part->Activate(CLSCTX_ALL, IID_PPV_ARGS(&jack)); if (SUCCEEDED(hr)) { UINT jackCount = 0; jack->GetJackCount(&jackCount); for (int j = 0; j < jackCount; j++) { KSJACK_DESCRIPTION desc = { 0 }; jack->GetJackDescription(j, &desc); wprintf(L" jack[%i] channel mapping: %i\n", j, desc.ChannelMapping); wprintf(L" jack[%i] connection type: %i\n", j, desc.ConnectionType); wprintf(L" jack[%i] is connected: %i\n", j, desc.IsConnected); wprintf(L" jack[%i] color: 0x%08X\n", j, desc.Color); } } } } } } } } } } enumerator.Release(); CoUninitialize(); return 0; }