3
votes

StringCbCat: http://msdn.microsoft.com/en-us/library/windows/desktop/ms647495%28v=vs.85%29.aspx StringCchCat: http://msdn.microsoft.com/en-us/library/windows/desktop/ms647518%28v=vs.85%29.aspx

Currently I am writing a C++ program to deal to TCHAR strings. I found this two Windows APIs, one is StringCbCat, the other is StringCchCat. Both of them seems to be able to do strcat() function for TCHAR strings. But if they are the same, why give them two different names? I tried google but no luck.

Anyone knows if there is any difference? Or they are just the same?

PS. The same goes for other StringCbxxx and StringCchxxx functions such as StringCbLength and StringCchLength

1
BTW, the "StrSafe" APIs are deprecated these days in favor of the "Secure CRT" so you'd use strcat_s(). Or rather you should use wcscat_s() because ASCII and TCHAR is also deprecated these days in favor of UNICODE. StrSafe can still be useful for targeting non-Microsoft platforms where the "Secure CRT" functions are not implemented. - Chuck Walbourn

1 Answers

11
votes

StringCbCat::

cbDest [in] Type: size_t The size of the destination buffer, in bytes. The maximum number of bytes allowed is STRSAFE_MAX_CCH * sizeof(TCHAR).

Example::

WCHAR wszTemp[10] ;
DWORD dwNumberOfBytes = 10 * sizeof(WCHAR) ;
// 10 * 2 = 20 Bytes. 
// 1 [WCHAR][2] takes 2 Bytes

StringCchCat::

cchDest [in] Type: size_t The size of the destination buffer, in characters. The maximum number of characters allowed is STRSAFE_MAX_CCH.

Example::

WCHAR wszTemp[10] ;
DWORD dwNumberOfCharacters = _countof(wszTemp) ;
// 10 Characters. 
// 1 [WCHAR][2] takes 2 Bytes that defines 1 character in UNICODE.