Declare Function lstrcpyn Lib "kernel32.dll" Alias "lstrcpynA" (ByVal lpString1 As Any, ByVal lpString2 As Any, ByVal iMaxLength As Long) As Long
lstrcpy copies one or more characters from one string into another string, followed by a terminating null character. Either string, instead of being a "real" string, can also be merely a pointer to a string instead. The target string must already have enough space to receive the source string's contents along with the terminating null.
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a non-zero value.
This function is very useful for "converting" a pointer to a string into an actual string.
' This code is licensed according to the terms and conditions listed here. ' Copy the first word source string to the target string Dim source As String, target As String ' the two strings Dim retval As Long ' return value source = "Hello, world!" ' the source string to copy target = Space(6) ' make room in target to receive the copied string retval = lstrcpy(target, source, 6) ' set target to equal source target = Left(target, Len(target) - 1) ' remove the terminating null character Debug.Print "Source string: "; source Debug.Print "Target string: "; target ' this should be "Hello"
lstrcpy
Strings
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: December 26, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/l/lstrcpyn.html