You are reading a single character (byte) into
Buff
. So you can't pass
Buff
where a NULL terminated string parameter is expected without appending the NULL terminator. Your code snippet indicates also that you are using a Unicode build. So the characters read from the serial port must be converted to Unicode. Using a
CString
, this can be done this way (when the received characters are plain ASCII or from the ANSI code page of your system):
CString msg;
msg.Format(L"%hc", Buff[0]);
Buff[1] = 0;
msg.Format(L"%hs", Buff);
The
h prefix tells the format function that the parameter is an ASCII/ANSI char or string and performs the conversion to Unicode.