以StringCbCat 和 StringCchCat为例:
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.
上述的_countof的宏定义:
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
使用安全字符串函数,需要#include <strsafe.h>头文件