Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
Resources
Strings
String Reference
Functions
 lstrlen Function

  Switch on low bandwidth view
lstrlen Function

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 note 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 Versionkernel32.dll
HeaderDeclared in Winbase.h, include Windows.h
Import libraryKernel32.lib
Minimum operating systems Windows 95, Windows NT 3.1
UnicodeImplemented as ANSI and Unicode versions.

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker