我调用了以下函数来打印出枚举音频端点的端点和友好名称:
void EPPrint(void)
{
HRESULT hr;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDeviceCollection *pCollection = NULL;
IMMDevice *pEp = NULL;
IPropertyStore *pProps =NULL;
UINT count;
PWSTR strID;
PROPVARIANT pv;
hr = CoCreateInstance(CLSID_MMDeviceEnumerator ,NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **)&pEnumerator);
hr = pEnumerator -> EnumAudioEndpoints(eRender,DEVICE_STATE_ACTIVE,&pCollection);
hr = pCollection ->GetCount(&count);
if(count==0)
{
}
for (ULONG i =0; i<count; ++i)
{
hr= pCollection->Item(i,&pEp);
hr = pEp ->GetId(&strID);
hr = pEp ->OpenPropertyStore(STGM_READ,&pProps);
PropVariantInit(&pv);
hr = pProps ->GetValue(PKEY_Device_FriendlyName, &pv);
printf("Enpoint %d: \"%S\" (%S)\n",i,pv.pwszVal, strID);
}
}
但是我收到运行时错误Unhandled exception at 0x008e104a in EPAudioControl.exe: 0xC0000005: Access violation reading location 0x00000000.
这打破了该hr = pEnumeartor -> ...
行的程序。
程序是否需要某种特殊的 Windows 权限才能正常运行?