Determines whether a string exceeds the specified length, in characters.
StringCchLength is a replacement for the following functions:
STRSAFEAPI StringCchLengthA( STRSAFE_PCNZCH psz, size_t cchMax, size_t *pcchLength );
The string whose length is to be checked.
The maximum number of characters allowed in psz, including the terminating null character. This value cannot exceed STRSAFE_MAX_CCH.
The number of characters in psz, not including the terminating null character. This value is valid only if pcch is not NULL and the function succeeds.
||The string at psz was not NULL, and the length of the string (including the terminating null character) is less than or equal to cchMax characters.|
||The value in psz is NULL, cchMax is larger than STRSAFE_MAX_CCH, or psz is longer than cchMax.|
Note that this function returns an HRESULT value, unlike the functions that it replaces.
Compared to the functions it replaces, StringCchLength is an additional tool for proper buffer handling in your code. Poor buffer handling is implicated in many security issues that involve buffer overruns.
StringCchLength can be used in its generic form, or in its more specific forms. The data type of the string determines the form of this function that you should use.
|String Data Type||String Literal||Function|
UnalignedStringCchLength is an alias for this function.
|Minimum supported client||Windows XP with SP2 [desktop apps | UWP apps]|
|Minimum supported server||Windows Server 2003 with SP1 [desktop apps | UWP apps]|