从 Windows 获取完整的音频设备名称

发布于 2024-08-04 15:46:31 字数 541 浏览 7 评论 0原文

有没有办法在 Windows XP 及更高版本中获取完整音频设备名称?

我可以使用 MIXERC​​APS,但 szPname 成员将限制为 32 个字符(包括 NULL)。对于音频设备名称“麦克风(高清晰度音频设备)”,我只得到“麦克风(高清晰度音频设备”)。这是由于MAXPNAMELEN被定义为32。我尝试将其重新定义为更大的数字,但没有效果 我

这是我正在使用的代码:

MIXERCAPS mc;
ZeroMemory( &mc, sizeof(MIXERCAPS) );
mm = mixerGetDevCaps( reinterpret_cast<UINT_PTR>(m_hMixer), &mc, sizeof(MIXERCAPS) );

看到了这个问题,但它参考 Vista 及更高版本。

Is there a way to get the full audio device name in Windows XP and later?

I can use MIXERCAPS but the szPname member will limit to 32 characters (including NULL). For an audio device name of "Microphone (High Definition Audio Device)", I only get back "Microphone (High Definition Aud". This is due to MAXPNAMELEN being defined to 32. I have tried redefining it to a larger number to no effect.

Here is the code I am using:

MIXERCAPS mc;
ZeroMemory( &mc, sizeof(MIXERCAPS) );
mm = mixerGetDevCaps( reinterpret_cast<UINT_PTR>(m_hMixer), &mc, sizeof(MIXERCAPS) );

I saw this question, but it references Vista and later.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千纸鹤 2024-08-11 15:46:31

如果您使用经典的 Windows 多媒体界面,您可能无法绕过 MAXPNAMELEN 限制,因为它已编译到 Windows 本身中。

但是,如果您使用 DirectSound,则可能可以获得完整的设备名称。以下代码未经测试,但我认为它应该有效。

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
    }
}

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
    }
}
浪漫之都 2024-08-11 15:46:31

下面是我的(Delphi)代码:

这是使用 DirectShow/ActiveX,
它枚举 DirectSound 设备,其中还包括包装的 WaveOut 设备。

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;

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;
阳光下慵懒的猫 2024-08-11 15:46:31

您可以尝试使用 devcon。可在 Microsoft 网站此处获取。

我认为 devcon listclass media 可能会给你你正在寻找的结果。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文