Get the full audio device name from Windows

孤人 提交于 2019-11-29 10:56:30

If you use the classic Windows Multimedia interface you probably can't get around the MAXPNAMELEN limitation, since that's compiled into Windows itself.

However you might be able to get the full device name if you use DirectSound instead. The following code is untested but I think it should work.

BOOL CALLBACK EnumCallback(LPGUID guid, LPCSTR descr, LPCSTR modname, LPVOID ctx)
{
    std::vector<std::string> *names = (std::vector<std::string>*)ctx;
    names->push_back(std::string(descr));
    return TRUE;
}

int main()
{
    std::vector<std::string> names;
    if (!FAILED(DirectSoundEnumerate(&EnumCallback, &names)))
    {
        // do stuff
    }
}

You could try using devcon. Available at Microsoft's site here.

I think devcon listclass media may give you the result you're looking for.

Below is my (Delphi) code:

This is using DirectShow/ActiveX, It enumurates DirectSound devices, which include wrapped WaveOut devices as well.

procedure EnumAudioDevices;
var
  dsCreateDevEnum  : ICreateDevEnum;
  EnumDevice       : IEnumMoniker;
  DeviceMoniker    : IMoniker;
  Data             : Integer;
  DevicePropBag    : IPropertyBag;
  DeviceName       : OLEVariant;
  I                : Integer;
begin
  // CLSID_CQzFilterClassManager = Entire DirectShow Filter List
  If CoCreateInstance(CLSID_SystemDeviceEnum,nil,CLSCTX_INPROC_SERVER,IID_ICreateDevEnum,dsCreateDevEnum) = S_OK then
  Begin
    If dsCreateDevEnum.CreateClassEnumerator(CLSID_AudioRendererCategory,EnumDevice,0) = S_OK then
    Begin
      I := 0;
      EnumDevice.Reset;
      While EnumDevice.Next(1,DeviceMoniker,@Data) = S_OK do
      Begin
        If DeviceMoniker.BindToStorage(nil,nil,IID_IPropertyBag,DevicePropBag) = NOERROR then
        Begin
          If DevicePropBag.Read('FriendlyName',DeviceName,nil) = NOERROR then
          Begin
            // Success
            ShowMessage(DeviceName);
            Inc(I);
          End;
          DevicePropBag := nil;
        End;
        DeviceMoniker := nil;
      End;
      EnumDevice := nil;
    End;
    dsCreateDevEnum := nil;
  End;
End;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!