lstrcpy Function

Declare Function lstrcpyn Lib "kernel32.dll" Alias "lstrcpynA" (ByVal lpString1 As Any, ByVal lpString2 As Any, ByVal iMaxLength As Long) As Long

Platforms

Description & Usage

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.

Return Value

If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a non-zero value.

Visual Basic-Specific Issues

This function is very useful for "converting" a pointer to a string into an actual string.

Parameters

lpString1
String that receives the copied contents of lpString2. This could be either the string itself or a pointer to the string.
lpString2
Either an actual string to copy into lpString1 or a pointer to the string to copy into lpString1.
iMaxLength
The number of characters to copy from lpString2 to lpString1, including the terminating null character added to the end. (For example, a value of 4 for this parameter would copy three characters from lpString2 and a null character into lpString1.

Example

' 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"

See Also

lstrcpy

Category

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