lstrcpyW function (winbase.h)
Copies a string to a buffer.
LPWSTR lstrcpyW( [out] LPWSTR lpString1, [in] LPCWSTR lpString2 );
A buffer to receive the contents of the string pointed to by the lpString2 parameter. The buffer must be large enough to contain the string, including the terminating null character.
The null-terminated string to be copied.
If the function succeeds, the return value is a pointer to the buffer.
If the function fails, the return value is NULL and lpString1 may not be null-terminated.
With a double-byte character set (DBCS) version of the system, this function can be used to copy a DBCS string.
The lstrcpy function has an undefined behavior if source and destination buffers overlap.
Security RemarksUsing this function incorrectly can compromise the security of your application. This function uses structured exception handling (SEH) to catch access violations and other errors. When this function catches SEH errors, it returns NULL without null-terminating the string and without notifying the caller of the error. The caller is not safe to assume that insufficient space is the error condition.
lpString1 must be large enough to hold lpString2 and the closing '\0', otherwise a buffer overrun may occur.
Buffer overflow situations are the cause of many security problems in applications and can cause a denial of service attack against the application if an access violation occurs. In the worst case, a buffer overrun may allow an attacker to inject executable code into your process, especially if lpString1 is a stack-based buffer.
Consider using StringCchCopy instead; use either
StringCchCopy(buffer, sizeof(buffer)/sizeof(buffer), src);,
being aware that
buffer must not be a pointer or
StringCchCopy(buffer, ARRAYSIZE(buffer), src);,
being aware that, when copying to a pointer, the caller is responsible for
passing in the size of the pointed-to memory in characters.
The winbase.h header defines lstrcpy as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
|Minimum supported client||Windows 2000 Professional [desktop apps only]|
|Minimum supported server||Windows 2000 Server [desktop apps only]|
|Header||winbase.h (include Windows.h)|