Just don't use the additional bytes. You usually know how many bytes has been received.
Allocate a
char*
buffer that is large enough to hold the maximum length of data (optionally plus one byte for a null terminator).
If you know that the data are printable characters and you want to create a string, you have to specify the length or append a null byte to the buffer.
To copy the data into a
CString
you can use
CString str(buffer, dwRead);
CStringA strA;
strA.SetString(buffer, dwRead);
Or append a null byte to the buffer:
ASSERT(dwRead < RX_BUF_SIZE);
buffer[dwRead] = 0;
CString str(buffer);