You can try to enumerate endpoints like in the test below, and if you don't get it, you can adapt the code from
(with WalkTreeBackwardsFromPart function)
{
CoInitialize(NULL);
IMMDeviceEnumerator* pDeviceEnumerator = NULL;
HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (void**)&pDeviceEnumerator);
if (hr == S_OK)
{
IMMDeviceCollection* pDeviceCollection = NULL;
hr = pDeviceEnumerator->EnumAudioEndpoints(eAll, DEVICE_STATE_ACTIVE | DEVICE_STATE_UNPLUGGED, &pDeviceCollection);
if (hr == S_OK)
{
UINT nDeviceCount = 0;
hr = pDeviceCollection->GetCount(&nDeviceCount);
for (UINT i = 0; i < nDeviceCount; i++)
{
IMMDevice* pDevice;
hr = pDeviceCollection->Item(i, &pDevice);
if (hr == S_OK)
{
TCHAR wsBuffer[255];
IPropertyStore* propertyStore;
hr = pDevice->OpenPropertyStore(STGM_READ, &propertyStore);
PROPVARIANT pvFriendlyName;
PropVariantInit(&pvFriendlyName);
hr = propertyStore->GetValue(PKEY_Device_FriendlyName, &pvFriendlyName);
TCHAR wsDeviceName[128];
hr = StringCbPrintf(wsDeviceName, sizeof(wsDeviceName), _T("%s"), pvFriendlyName.vt != VT_LPWSTR ? _T("Unknown") : pvFriendlyName.pwszVal);
PropVariantClear(&pvFriendlyName);
wsprintf(wsBuffer, _T("Device Name : %s\r\n"), wsDeviceName);
OutputDebugString(wsBuffer);
IMMEndpoint* pEndpoint;
EDataFlow flow;
pDevice->QueryInterface<IMMEndpoint>(&pEndpoint);
pEndpoint->GetDataFlow(&flow);
pEndpoint->Release();
LPWSTR pwsDeviceId;
hr = pDevice->GetId(&pwsDeviceId);
wsprintf(wsBuffer, _T("\tDevice Id : %s\r\n"), pwsDeviceId);
OutputDebugString(wsBuffer);
CoTaskMemFree(pwsDeviceId);
TCHAR wsFlow[255];
switch (flow) {
case EDataFlow::eRender:
lstrcpy(wsFlow, _T("Output"));
break;
case EDataFlow::eCapture:
lstrcpy(wsFlow, _T("Input"));
break;
case EDataFlow::eAll:
lstrcpy(wsFlow, _T("Input/Output"));
break;
}
wsprintf(wsBuffer, _T("\tFlow : %s\r\n"), wsFlow);
OutputDebugString(wsBuffer);
IAudioEndpointVolume* pEndptVol = NULL;
float nVolume = 0;
hr = pDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL, (void**)&pEndptVol);
if (hr == S_OK)
{
hr = pEndptVol->GetMasterVolumeLevelScalar(&nVolume);
pEndptVol->Release();
}
hr = StringCbPrintf(wsBuffer, sizeof(wsBuffer), _T("\tVolume : %.4lf\r\n"), nVolume);
OutputDebugString(wsBuffer);
pDevice->Release();
}
}
pDeviceCollection->Release();
}
pDeviceEnumerator->Release();
}
CoUninitialize();
}