5 out of 5 rated this helpful - Rate this topic

lstrlen function

Applies to: desktop apps only

Determines the length of the specified string (not including the terminating null character).

Syntax

int WINAPI lstrlen(
  __in  LPCTSTR lpString
);

Parameters

lpString [in]

Type: LPCTSTR

The null-terminated string to be checked.

Return value

Type: int

The function returns the length of the string, in characters. If lpString is NULL, the function returns 0.

Security Considerations

Security Warning

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.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

lstrlenW (Unicode) and lstrlenA (ANSI)

See also

Reference
StringCbLength
StringCchLength
lstrcat
lstrcmp
lstrcmpi
lstrcpy
Conceptual
Strings

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
use wcslen() instead of StringCchLength()/StringCbLength()
StringCchLength()/StringCbLength() are designed to take untrused input. lstrlen() and wcslen() are not. if you are using lstrlen() and know the pointer is not null use wcslen() instead.