Skip to content

Latest commit

 

History

History
162 lines (127 loc) · 4.77 KB

nf-strsafe-stringcchlengtha.md

File metadata and controls

162 lines (127 loc) · 4.77 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:strsafe.StringCchLengthA
StringCchLengthA function (strsafe.h)
Determines whether a string exceeds the specified length, in characters. (ANSI)
StringCchLengthA
strsafe/StringCchLengthA
menurc\stringcchlength.htm
menurc
VS|winui|~\winui\windowsuserinterface\resources\strings\stringreference\stringfunctions\stringcchlength.htm
12/05/2018
StringCchLength, StringCchLength function [Menus and Other Resources], StringCchLengthA, StringCchLengthW, UnalignedStringCchLength, _shell_StringCchLength, _shell_stringcchlength_cpp, menurc.stringcchlength, strsafe/StringCchLength, strsafe/StringCchLengthA, strsafe/StringCchLengthW, winui._shell_stringcchlength
strsafe.h
Windows
Windows XP with SP2 [desktop apps \| UWP apps]
Windows Server 2003 with SP1 [desktop apps \| UWP apps]
StringCchLengthW (Unicode) and StringCchLengthA (ANSI)
Windows
19H1
StringCchLengthA
strsafe/StringCchLengthA
c++
APIRef
kbSyntax
HeaderDef
Strsafe.h
StringCchLength
StringCchLengthA
StringCchLengthW

StringCchLengthA function

-description

Determines whether a string exceeds the specified length, in characters.

StringCchLength is a replacement for the following functions:

-parameters

-param psz [in]

Type: LPCTSTR

The string whose length is to be checked.

-param cchMax [in]

Type: size_t

The maximum number of characters allowed in psz, including the terminating null character. This value cannot exceed STRSAFE_MAX_CCH.

-param pcchLength [out]

Type: size_t*

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.

-returns

Type: HRESULT

This function can return one of the following values. It is strongly recommended that you use the SUCCEEDED and FAILED macros to test the return value of this function.

Return code Description
S_OK
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.
STRSAFE_E_INVALID_PARAMETER
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.

-remarks

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
char "string" StringCchLengthA
TCHAR TEXT("string") StringCchLength
WCHAR L"string" StringCchLengthW
 

UnalignedStringCchLength is an alias for this function.

Note

The strsafe.h header defines StringCchLength as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

-see-also

StringCbLength