请输入您要查询的百科知识:

 

词条 StringCchLength
释义

StringCchLength Function

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

判断字符串是否在字符数量上超出指定的长度.

StringCchLength is a replacement for the following functions:

StringCchLength 是下面函数的替代

strlen, wcslen, _tcslen

Syntax语法

HRESULT StringCchLength( __in LPCTSTR psz, __in size_t cchMax, __out size_t *pcch);

Parameters参数

psz [in] LPCTSTRThe string whose length is to be checked.

指向被检查的字符串的指针.

cchMax [in] size_tThe maximum number of characters allowed in psz, including the terminating null character. This value cannot exceed STRSAFE_MAX_CCH.

psz里最大允许的字符数量,包括结尾的null字符,这个数量不能超过STRSAFE_MAX_CCH

pcch [out] size_tThe 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.

psz里的字符数量,不包括结尾的null字符,这个值只有在pcch指针不为null,且函数成功时有效

Return Value返回值

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.

这个函数可能返回下面这些值,强烈建议您使用SUCCEEDED和FAILED宏来测试这个函数的返回值.

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.
psz指向的字符串不为空,并且字符串的长度(包括结尾null字符)小于或等于cchMax

STRSAFE_E_INVALID_PARAMETER 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.
psz指向的字符串不为空,并且字符串的长度(包括结尾null字符)小于或等于cchMax

Note that this function returns an HRESULT value, unlike the functions that it replaces.

请注意:这个函数返回的是一个HRESULT值,而不是它要替代的函数所返回的size_t

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是在您代码里,正确处理缓存区的一个附加功能,因为小缓冲处理会牵连很多安全问题,例如缓存区溢出

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.

StringCchLength可以以笼统的格式使用,或者特殊的格式,字符串里的字符类型决定您应该使用的函数类型

String Data Type
字符串里的字符类型 String Literal
字面字符串 Function
函数

char "string" StringCchLengthA

TCHAR TEXT("string") StringCchLength

WCHAR L"string" StringCchLengthW

Requirements需求

Minimum supported client
最低支持的客户端版本 Windows XP with SP2

Minimum supported server
最低支持的服务器版本 Windows Server 2003 with SP1

Header
头文件 Strsafe.h

Unicode and ANSI names
Unicode和ASNI函数名 StringCchLengthW (Unicode) and StringCchLengthA (ANSI)

See Also参见

StringCbLength

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/1/9 9:23:20