You have to reserve space for string terminator (NULL character too), this line will allocate space for string only, without terminator:
pDeviceInfo[nDevices].lpszDesc = new WCHAR[wcslen(lpszDesc)];
This because wcslen()
returns string length without terminator (see reference). Just change to (for all strings, of course):
pDeviceInfo[nDevices].lpszDesc = new WCHAR[wcslen(lpszDesc) + 1];
pDeviceInfo[nDevices].lpszDevName = new WCHAR[wcslen(lpszDevName) + 1];
And:
ZeroMemory(pDeviceInfo[nDevices].lpszDesc, sizeof(WCHAR) * (wcslen(lpszDesc) + 1));
ZeroMemory(pDeviceInfo[nDevices].lpszDevName, sizeof(WCHAR) * (wcslen(lpszDevName) + 1));