How do I get the byte size of a multibyte-character string in Visual C? Is there a function or do I have to count the characters myself?
Or, more general, how do I get the right byte size of a TCHAR string?
Solution:
_tcslen(_T("TCHAR string")) * sizeof(TCHAR)
EDIT:
I was talking about null-terminated strings only.
According to MSDN,
_tcslencorresponds tostrlenwhen_MBCSis defined.strlenwill return the number of bytes in the string. If you use_tcsclenthat corresponds to_mbslenwhich returns the number of multibyte characters.Also, multibyte strings do not (AFAIK) contain embedded nulls, no.
I would question the use of a multibyte encoding in the first place, though… unless you’re supporting a legacy app, there’s no reason to choose multibyte over Unicode.