Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a CString always null-terminated?

Tags:

mfc

cstring

From the CString interface, clearly one should not assume that a CString is null-terminated. However, it seems that sometimes there is, in fact, a null character at the end of the string. Is it possible, in the Windows implementation, to create a CString that does not have a null character, so that reading one character past the end of the string is looking at a different heap object?

like image 901
Tim Culver Avatar asked Sep 10 '25 23:09

Tim Culver


1 Answers

Yes, the CString is always null terminated.

The documentation states that the you can cast a CString to LPCTSTR, and LPCTSTR is a typedef to one of:
__nullterminated CONST WCHAR *
__nullterminated CONST CHAR *
depending on whether UNICODE is defined or not.

like image 142
Knyphe Avatar answered Sep 13 '25 08:09

Knyphe