UnalignedStringCbLength function

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

The function is similar to StringCbLength, but it accepts an unaligned string pointer.


HRESULT UnalignedStringCbLength(
  _In_      LPCTSTR psz,
  _In_      size_t  cbMax,
  _Out_opt_ size_t  *pcbLength


psz [in]

The string whose length is to be checked.

cbMax [in]

The maximum number of bytes allowed in psz, including those used for the terminating null character. This value cannot exceed STRSAFE_MAX_CCH * sizeof(TCHAR).

pcbLength [out, optional]

The number of bytes in psz, excluding those used for the terminating null character. This value is valid only if pcb is not NULL and the function succeeds.

Return value

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 codeDescription

The string at psz was not NULL, and the length of the string (including the terminating null character) is less than or equal to cbMax characters.


The value in psz is NULL, cbMax is larger than STRSAFE_MAX_CCH * sizeof(TCHAR), or psz is longer than cbMax.



Minimum supported client

Windows Vista [desktop apps | UWP apps]

Minimum supported server

Windows Server 2008 [desktop apps | UWP apps]



Unicode and ANSI names

UnalignedStringCbLengthW (Unicode) and StringCbLengthA (ANSI)