I am trying to write a program that interfaces with Windows Core Audio and WASAPI. I am having difficulty with the following couple lines.
CComHeapPtr<WCHAR> name;
hr = pAudioSessionControl->GetDisplayName(&name);
if (FAILED(hr)) {
LOG(L"IAudioSessionControl::GetDisplayName() failed: hr = 0x%08x", hr);
return -__LINE__; }
_tprintf(_T("Session Index %d, \"%s\"\n"), i, CString(name));
Outputs:
Session Index 0, "@%SystemRoot%\System32\AudioSrv.Dll,-202"
Session Index 1, ""
Session Index 2, ""
Session Index 3, ""
Press any key to continue . . .
This is with 3 programs all active and making noise. It seems i can see the system sounds program but nothing else.
Thanks for the help.
IAudioSessionControl::GetDisplayName
is proper API and it might return non-empty strings, however you might also see inactive sessions for which the strings are indeed empty. In your case you might hit inactive sessions, error code which you did not provide or otherwise incorrect API use.This code snippet/application enumerates sessions and polls for volume changes - it prints non-empty strings.