This function returns the length in bytes (ANSI version) or WCHAR values (Unicode version) of the specified string (not including the terminating null character).
Syntax
int lstrlen(
LPCTSTR lpString
);
Parameters
- lpString
-
[in] Pointer to a null-terminated string.
Return Value
The return value specifies the length of the string, in TCHAR values. This refers to bytes for ANSI versions of the function or WCHAR values for Unicode versions. If lpString is NULL, the return value is 0.
Remarks
Security Alert Using this function incorrectly can compromise the security of your application. lstrlen assumes that lpString is a null-terminated string, or NULL. If it is not, this could lead to a buffer overrun or a denial of service attack against your application.
Consider using one of the following alternatives: StringCbLength or StringCchLength.
Review Security Considerations: Windows User Interface before continuing.
Windows 95/98/Me: Although lstrlenW exists on Microsoft Windows 95/98/Me, it is supported by the Microsoft Layer for Unicode (MSLU) to give more consistent behavior across all Windows operating systems. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
Example
For an example, see Displaying Keyboard Input.
Function Information
| Minimum DLL Version | kernel32.dll |
|---|
| Header | Declared in Winbase.h, include Windows.h |
|---|
| Import library | Kernel32.lib |
|---|
| Minimum operating systems |
Windows 95, Windows NT 3.1 |
|---|
| Unicode | Implemented as
ANSI and Unicode versions. |
|---|
See Also