网站首页  词典首页

请输入您要查询的函数:

 

术语 stringcchcopyn
释义 StringCchCopyN
语法:
HRESULT StringCchCopyN( LPTSTR pszDest,
size_t cchDest,
LPCTSTR pszSrc,
size_t cchSrc
);
StringCchCopyN功能
StringCchCopyN是一个strncpy替代。 StringCchCopyN复制从源字符串中的字符数。大小,以字符缓冲区的目标是提供的功能,以确保不会写入StringCchCopyN过去这个缓冲区的末尾。
参数
pszDest
[out]指向它接收缓冲区复制的字符。
cchDest
[in]的pszDest大小,以字符。此值必须大到足以容纳复制的字符(即pszSrc或cchSrc价值,以较少者为准),加上1至占终止空字符的长度。所允许的最大字符数为STRSAFE_MAX_CCH。
pszSrc
[in]指向一个缓冲区包含源字符串。此源字符串必须空终止。
cchSrc
[in]的最大字符数从pszSrc复制到pszDest。
返回值
请注意,此函数返回,而不是strncpy,它返回一个指针的hresult。我们强烈建议您使用的成功和失败宏来测试这个函数的返回值。
S_OKSource数据目前,被复制的字符从pszSrc没有截断,并由此产生的目标缓冲区是空终止。
STRSAFE_E_INVALID_PARAMETERThe在cchDest值是比STRSAFE_MAX_CCH,或目标缓冲区大已经爆满。
STRSAFE_E_INSUFFICIENT_BUFFERThe复制操作失败,由于没有足够的缓冲空间。目标缓冲区包含了预期的结果被截断,空终止的版本。截断的情况下是可以接受的,这未必是一个失败的情况出现。
备注
StringCchCopyN提供了代码中的适当缓冲处理额外的处理。可怜的缓冲处理是牵连,许多安全问题涉及缓冲区溢出。 StringCchCopyN总是空终止一个非零长度目标缓冲区。
StringCchCopyN可以用在它的通用形式,或作为StringCchCopyNA特别(为ANSI字符串)或StringCchCopyNW(为Unicode字符串)。该表格使用取决于您的数据。
字符串数据String类型LiteralFunction
字符“字符串”StringCchCopyNA
TCHARTEXT(“字符串”)StringCchCopyN
WCHARL“字符串”StringCchCopyNW
虽然这个程序是作为strncpy替代意味着,在行为上存在的分歧。如果大于cchSrc中的字符pszSrc,StringCchCopyN人数不像strncpy,不会继续空字符填充pszDest直到cchSrc字符被复制。
行为是未定义如果字符串指向pszSrc和pszDest重叠。
无论pszSrc也不pszDest应为NULL。见StringCchCopyNEx如果您需要的空字符串指针值的处理。
功能信息
Headerstrsafe.h
import librarystrsafe.lib
参见
StringCbCopyN,StringCchCopyNEx,StringCchCopy
==英文原文==StringCchCopyN Function
StringCchCopyN is a replacement for strncpy . StringCchCopyN copies a given number of characters from a source string. The size, in characters, of the destination buffer is provided to the function to ensure that StringCchCopyN does not write past the end of this buffer.
Syntax
HRESULT StringCchCopyN( LPTSTR pszDest,
size_t cchDest,
LPCTSTR pszSrc,
size_t cchSrc
);
Parameters
pszDest
[out] Pointer to a buffer which receives the copied characters.
cchDest
[in] Size of pszDest, in characters. This value must be large enough to hold the copied characters (the length of pszSrc or the value of cchSrc, whichever is smaller) plus 1 to account for the terminating null character. The maximum number of characters allowed is STRSAFE_MAX_CCH.
pszSrc
[in] Pointer to a buffer containing the source string. This source string must be null-terminated.
cchSrc
[in] The maximum number of characters to copy from pszSrc to pszDest.
Return Value
Note that this function returns an HRESULT as opposed to strncpy, which returns a pointer. It is strongly recommended that you use the SUCCEEDED and FAILED macros to test the return value of this function.
S_OKSource data was present, the characters were copied from pszSrc without truncation, and the resultant destination buffer is null-terminated.
STRSAFE_E_INVALID_PARAMETERThe value in cchDest is either larger than STRSAFE_MAX_CCH, or the destination buffer is already full.
STRSAFE_E_INSUFFICIENT_BUFFERThe copy operation failed due to insufficient buffer space. The destination buffer contains a truncated, null-terminated version of the intended result. In situations where truncation is acceptable, this may not necessarily be seen as a failure condition.
Remarks
StringCchCopyN provides additional processing for proper buffer handling in your code. Poor buffer handling is implicated in many security issues that involve buffer overruns. StringCchCopyN always null-terminates a non-zero-length destination buffer.
StringCchCopyN can be used in its generic form, or specifically as StringCchCopyNA (for ANSI strings) or StringCchCopyNW (for Unicode strings). The form to use is determined by your data.
String Data TypeString LiteralFunction
char"string"StringCchCopyNA
TCHARTEXT("string")StringCchCopyN
WCHARL"string"StringCchCopyNW
While this routine is meant as a replacement for strncpy, there are differences in behavior. If cchSrc is larger than the number of characters in pszSrc, StringCchCopyN—unlike strncpy—does not continue to pad pszDest with null characters until cchSrc characters have been copied.
Behavior is undefined if the strings pointed to by pszSrc and pszDest overlap.
Neither pszSrc nor pszDest should be NULL. See StringCchCopyNEx if you require the handling of null string pointer values.
Function Information
Headerstrsafe.h
Import librarystrsafe.lib
See Also
StringCbCopyN , StringCchCopyNEx , StringCchCopy
==原始网址==http://msdn.microsoft.com/en-us/library/ms647530(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 13:21:45