网站首页  词典首页

请输入您要查询的函数:

 

术语 lstrcpyn
释义 lstrcpyn
语法:
LPTSTR lstrcpyn( LPTSTR lpString1,
LPCTSTR lpString2,
int iMaxLength
);
lstrcpyn函数
这个函数复制的字符从一个到缓冲区源字符串指定数目。
参数
lpString1
[out]指向的缓冲区的函数拷贝字符。该缓冲区必须足够大,以包含数字值的TCHAR指定iMaxLength,包括终止NULL字符的空间。
lpString2
[in]指向一个空结束的字符串函数从该份字符。
iMaxLength
[in]指定TCHAR值的数目要复制从字符串中指出lpString2到到缓冲区指出lpString1的,其中包括终止空字符。这是指对功能或宽字符的ANSI版本字节Unicode版本的值。
返回值
如果函数成功,返回值是对缓冲区的指针。该函数可以取得成功,即使源字符串大于iMaxLength字符的。
如果函数失败,返回值为NULL和lpString1不得空终止。
备注
安全警告:
使用此功能不当,可能会损害您的应用程序的安全。此函数使用结构化异常处理(SEH)捕获的访问冲突和其他错误。当这个函数捕捉SEH的错误,则返回空不空结束的字符串,而没有通知错误的来电。调用方没有把握地说,没有足够的空间是错误的条件。
如果缓冲区指向lpString1不够大,无法复制到包含字符串,可能会出现缓冲区溢出。当复制整个字符串,请注意sizeof返回的字节数。例如,如果lpString1指向一个缓冲区szString1这是TCHAR szString [100]宣布,那么sizeof(szString1)提供了以字节为单位,而不是宽字符,缓冲区的大小,可能导致一个Unicode版本的缓冲区溢出功能。
缓冲区溢出的情况是,在许多应用安全问题的原因,可引起拒绝服务攻击的应用程序对拒绝,如果发生访问冲突。在最坏的情况下,缓冲区溢出可能允许攻击者注入到可执行代码的过程中,特别是如果lpString1是一个基于堆栈的缓冲区。
使用sizeof(szString1)/ sizeof(szString1 [0])给出适当大小的缓冲区。
考虑使用StringCchCopy代替;使用任何StringCchCopy(缓冲区,钢骨混凝土,sizeof(缓冲区)/ sizeof(缓冲区[0]);,明知不可缓冲区指针或使用StringCchCopy(缓冲,钢骨混凝土,ARRAYSIZE(缓冲区),意识到,当复制到一个指针,调用者负责在指向的内存大小的字符传递。
审查安全方面的考虑:Windows用户界面,然后继续。
缓冲区指向lpString1必须足够大,以包括终止空字符和字符串的长度值iMaxLength包括终止NULL字符的空间指定。下面的代码复制字符串“abc”,随后终止空字符,以chBuffer。
TCHAR chBuffer [512];
lstrcpyn(chBuffer,“abcdefghijklmnop”,4);

该lstrcpyn函数有一个未定义的行为,如果源和目标缓冲区重叠。
在Windows 95/98/Me:lstrcpynW是支持的Unicode(MSLU)微软层。要使用此,您必须将某些文件到您的应用,概述了对Unicode的Microsoft层在Windows 95/98/Me系统。
功能信息
最低DLL版本 kernel32.dll
在Winbase.h HeaderDeclared,头文件:winuser.h
import libraryKernel32.lib
最低操作系统Windows 95,Windows NT 3.5
UnicodeImplemented为ANSI和Unicode版本。
参见
Strings 概述 ,StringCbCopy,StringCbCopyEx,StringCbCopyN,StringCbCopyNEx,StringCchCopy,StringCchCopyEx,StringCchCopyN,StringCchCopyNEx,StringCbLength,StringCchLength,lstrcat,lstrcmp,lstrcmpi,lstrcpy,lstrlen
==英文原文==lstrcpyn Function
This function copies a specified number of characters from a source string into a buffer.
Syntax
LPTSTR lstrcpyn( LPTSTR lpString1,
LPCTSTR lpString2,
int iMaxLength
);
Parameters
lpString1
[out] Pointer to a buffer into which the function copies characters. The buffer must be large enough to contain the number of TCHAR values specified by iMaxLength, including room for a terminating null character.
lpString2
[in] Pointer to a null-terminated string from which the function copies characters.
iMaxLength
[in] Specifies the number of TCHAR values to be copied from the string pointed to by lpString2 into the buffer pointed to by lpString1, including a terminating null character. This refers to bytes for ANSI versions of the function or WCHAR values for Unicode versions.
Return Value
If the function succeeds, the return value is a pointer to the buffer. The function can succeed even if the source string is greater than iMaxLength characters.
If the function fails, the return value is NULL and lpString1 may not be null-terminated.
Remarks
Security Alert
Using 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.
If the buffer pointed to by lpString1 is not large enough to contain the copied string, a buffer overrun can occur. When copying an entire string, note that sizeof returns the number of bytes. For example, if lpString1 points to a buffer szString1 which is declared as TCHAR szString[100], then sizeof(szString1) gives the size of the buffer in bytes rather than WCHAR, which could lead to a buffer overflow for the Unicode version of the function.
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.
Using sizeof(szString1)/sizeof(szString1[0]) gives the proper size of the buffer.
Consider using StringCchCopy instead; use either StringCchCopy(buffer, src, sizeof(buffer)/sizeof(buffer[0]);, being aware that buffer must not be a pointer or use StringCchCopy(buffer, src, ARRAYSIZE(buffer);, being aware that, when copying to a pointer, the caller is responsible for passing in the size of the pointed-to memory in characters.
Review Security Considerations: Windows User Interface before continuing.
The buffer pointed to by lpString1 must be large enough to include a terminating null character, and the string length value specified by iMaxLength includes room for a terminating null character. The following code copies the string "abc", followed by a terminating null character, to chBuffer.
TCHAR chBuffer[512];
lstrcpyn(chBuffer, "abcdefghijklmnop", 4);

The lstrcpyn function has an undefined behavior if source and destination buffers overlap.
Windows 95/98/Me: lstrcpynW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems .
Function Information
Minimum DLL Versionkernel32.dll
HeaderDeclared in Winbase.h, include Windows.h
Import libraryKernel32.lib
Minimum operating systemsWindows 95, Windows NT 3.5
UnicodeImplemented as ANSI and Unicode versions.
See Also
Strings Overview , StringCbCopy , StringCbCopyEx , StringCbCopyN , StringCbCopyNEx , StringCchCopy , StringCchCopyEx , StringCchCopyN , StringCchCopyNEx , StringCbLength , StringCchLength , lstrcat , lstrcmp , lstrcmpi , lstrcpy , lstrlen
==原始网址==http://msdn.microsoft.com/en-us/library/ms647491(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 9:23:54