windows-7 - waveOutGetDevCaps,Win7和长设备名

标签 windows-7 audio

我维护的旧代码库使用waveOutGetDevCaps来获取系统上音频设备的名称。在Windows 7计算机上,这导致名称被截断,因为WAVEOUTCAPS.szPname受MAXPNAMELEN(31个字符)限制。

Win7这样做的方式是什么?

最佳答案

您可以使用以下一种核心音频API:

// get the device enumerator
IMMDeviceEnumerator* pEnumerator = NULL;
HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL,
                              CLSCTX_ALL,__uuidof(IMMDeviceEnumerator),
                              (void**)&pEnumerator);

// get the endpoint collection
IMMDeviceCollection* pCollection = NULL;
DWORD mask = DEVICE_STATE_ACTIVE || DEVICE_STATE_UNPLUGGED;
hr = pEnumerator->EnumAudioEndpoints(eRender, mask, &pCollection);

// get the size of the collection
UINT count = 0;
hr = pCollection->GetCount(&count);

for (int i = 0; i < (int)count; i++)
{
    // get the endpoint
    IMMDevice* pEndPoint = NULL;
    hr = pCollection->Item(i, &pEndPoint);

    // get the human readable name
    String^ friendlyName;
    IPropertyStore* pProps = NULL;
    HRESULT hr = pEndPoint->OpenPropertyStore(STGM_READ, &pProps);
    PROPVARIANT varName;
    PropVariantInit(&varName);
    hr = pProps->GetValue(PKEY_Device_FriendlyName, &varName);
    friendlyName = gcnew String(varName.pwszVal);
    PropVariantClear(&varName);
}       

上面的代码中删除了错误处理,以提高可读性。 (我碰巧喜欢使用C++ / CLI在C#和Windows API之间移动。)

现在,更难的部分将是将端点名称与旧代码库中的MME设备相关联。

关于windows-7 - waveOutGetDevCaps,Win7和长设备名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5111797/

相关文章:

python - 我正在尝试获取当前在 Windows 7 上使用 Python 运行的所有进程和应用程序

mysql - 在 MySQL 命令行中,如何仅使用键盘从剪贴板粘贴?

ruby-on-rails - Firefox不支持HTTP “Content-Type” “application/octet-stream”

java - 创建新的随机音频文件时,播放随机音频onClick不会重置-Android

.net - 使用.net API将音频实时流传输到android客户端的最佳方法是什么

c# - 高性能网络应用的最佳实践

c# - 如何使用我的个人电脑在 windows iis 服务器上发布我的网站?

python - 为什么 Windows7 中的 hadoop 会引发 RuntimeException : Error in configuring object

audio - Pyaudio声音质量问题

matlab - MATLAB中的低通滤波器返回NaN值