StringCbCat (Windows Embedded CE 6.0)
1/5/2010
This function concatenates two strings. The StringCbCat functions are replacements for strcat and its related variants.
The size, in bytes, of the destination buffer is provided to the function to ensure that StringCbCat does not write past the end of this buffer.
Syntax
HRESULT StringCbCat(
LPTSTR pszDest,
size_t cbDestest,
LPCTSTR pszSrc
);
Parameters
pszDest
[in, out] Pointer to a buffer containing the string that pszSrc is concatenated to, and which contains the entire resultant string.The string at pszSrc is added to the end of the string at pszDest.
cbDest
[in] Size of the destination buffer, in bytes.This value must consider the length of pszSrc, plus the length of pszDest, plus the terminating null character.
The maximum number of bytes allowed is STRSAFE_MAX_CCH * sizeof(TCHAR).
pszSrc
[in] Pointer to a buffer containing the source string that is concatenated to the end of pszDest.This source string must be null-terminated.
Return Value
This function returns an HRESULT as opposed to strcat, which returns a pointer.
It is strongly recommended that you use the SUCCEEDED and FAILED macros to test the return value of this function.
Value | Description |
---|---|
S_OK |
Source data was present, the strings were fully concatenated without truncation, and the resultant destination buffer is null-terminated. |
STRSAFE_E_INVALID_PARAMETER |
The value in cbDest is 0, larger than the maximum allowed value, or smaller than the actual size of pszDest. |
STRSAFE_E_INSUFFICIENT_BUFFER |
The concatenation operation failed due to insufficient buffer space. The destination buffer contains a truncated, null-terminated version of the intended result. Where truncation is acceptable, this is not necessarily a failure condition. |
Remarks
StringCbCat provides additional processing for proper buffer handling in your code. Poor buffer handling is implicated in many security issues that involve buffer overruns. It always null-terminates a nonzero-length destination buffer.
StringCbCat can be used in its generic form, or specifically as StringCbCatA (for ANSI strings) or StringCbCatW (for Unicode strings). The form to use is determined by your data.
String data type | String literal | Function |
---|---|---|
char |
"string" |
StringCbCatA |
TCHAR |
TEXT("string") |
StringCbCat |
WCHAR |
L"string" |
StringCbCatW |
StringCbCat and its ANSI and Unicode variants are replacements for these functions:
- strcat
- wcscat
Behavior is undefined if the strings pointed to by pszSrc and pszDest overlap.
Neither pszSrc nor pszDest should be NULL. If you need the handling of null string pointer values, see StringCbCatEx.
Requirements
Header | strsafe.h |
Windows Embedded CE | Windows CE 5.0 and later |
See Also
Reference
StrSafe.h Byte-Count Functions
StringCchCat
StringCbCatEx
StringCbCatN