StringCchLength

StringCchLength,是判斷字元串是否在字元數量上超出指定的長度的函式

基本介紹

  • 中文名:判斷字元串是否在字元數量上超出指定的長度
  • 外文名:StringCchLength
  • 函式strlen, wcslen, _tcslen
  • 語法:HRESULT StringCchLength
  • 返回值HRESULT
StringCchLength Function,Syntax語法,Parameters參數,Remarks請注意,Requirements需求,See Also參見,

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,且函式成功時有效
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

相關詞條

熱門詞條

聯絡我們