Unicode chars are 2 bytes wide.
if length holds the count in bytes then you may read a shorter string and miss the ending null. Because of this other operations on string can runover the allocated space corrupting the stack. In this case change:
ReadBytes(buffer, length);
to
ReadBytes(buffer, length*sizeof(wchar_t));
If length hold the count of chars the same problem could happen because the string length and the number of bytes are no more coincident.
In this case maybe you want change:
data = std::wstring(buffer,length);
With:
data = std::wstring(buffer,length/sizeof(wchar_t));