我正在枚举所有 DirectSound 输出设备并存储它们的描述以供以后在我的进程运行时使用。当我使用 OutputDebugStringW 检查结果时,我得到了正确的设备名称,但它附加了不必要的问号。即这个...
BOOL CALLBACK AudioPrivate::DSEnumProc(LPGUID lpGUID,
LPCWSTR lpszDesc,
LPCWSTR lpszDevName,
LPVOID lpData) {
pDeviceInfo[nDevices].lpGUID = lpGUID;
pDeviceInfo[nDevices].lpszDesc = new WCHAR[wcslen(lpszDesc)];
pDeviceInfo[nDevices].lpszDevName = new WCHAR[wcslen(lpszDevName)];
ZeroMemory(pDeviceInfo[nDevices].lpszDesc, sizeof(WCHAR) * wcslen(lpszDesc));
ZeroMemory(pDeviceInfo[nDevices].lpszDevName, sizeof(WCHAR) * wcslen(lpszDevName));
memcpy(pDeviceInfo[nDevices].lpszDesc, lpszDesc, sizeof(WCHAR) * wcslen(lpszDesc));
memcpy(pDeviceInfo[nDevices].lpszDevName, lpszDevName, sizeof(WCHAR) * wcslen(lpszDevName));
OutputDebugStringW(L"\n");
OutputDebugStringW(pDeviceInfo[nDevices].lpszDesc);
OutputDebugStringW(L"\n");
OutputDebugStringW(pDeviceInfo[nDevices].lpszDevName);
OutputDebugStringW(L"\n");
//vs
OutputDebugString(L"\n");
OutputDebugStringW(lpszDesc);
OutputDebugStringW(L"\n");
OutputDebugStringW(lpszDevName);
OutputDebugStringW(L"\n");
nDevices++;
return TRUE;
}
...结果:
Primary Sound Driver????????????
????????
Primary Sound Driver
Speakers (Conexant SmartAudio HD)???????????
{0.0.0.00000000}.{0698bbc7-d0ba-4445-a5a7-a63b625c4298}?????????
Speakers (Conexant SmartAudio HD)
{0.0.0.00000000}.{0698bbc7-d0ba-4445-a5a7-a63b625c4298}
我正在将内存清空到我自己的字符串中,因此只有在 Enum Proc 提供的字符串中包含这些问号时才会发生这种情况,但正如所证明的那样,它们没有。为什么会这样?