术语 | stringcchprintfex |
释义 | StringCchPrintfEx 语法: HRESULT StringCchPrintfEx( LPTSTR pszDest, size_t cchDest, LPTSTR *ppszDestEnd, size_t *pcchRemaining, DWORD dwFlags, LPCTSTR pszFormat, ... ); StringCchPrintfEx功能 StringCchPrintfEx是一个sprintf更换。它接受一个格式字符串和参数,并返回一个格式化字符串列表。大小,以字符缓冲区的目标是提供的功能,以确保不会写入StringCchPrintfEx过去这个缓冲区的末尾。 StringCchPrintfEx增加了StringCchPrintf功能通过返回一个指向目标字符串的结束以及闲置字符数在该字符串。旗也可以传递给函数的额外控制。 参数 pszDest [out]指向一个缓冲区的接收格式,NULL结尾的字符串从pszFormat和它的参数创建。 cchDest [in]的目标缓冲区的大小,以字符。此值必须足够大,以满足最终格式化字符串加1占终止空字符。所允许的最大字符数为STRSAFE_MAX_CCH。 ppszDestEnd [内]的指针地址的pszDest结束。如果ppszDestEnd不为NULL和任何数据到目标缓冲区复制的,在该字符串的结束点,终止空字符。 pcchRemaining [out]指向一个变量,它指示在pszDest人数未使用的字符,包括终止空字符。如果pcchRemaining为NULL,则计数不保留或退回。 dwFlags [in]一个或多个下列值。 STRSAFE_FILL_BEHIND_NULL 如果函数成功,在dwFlags(0)低字节是用来填补pszDest以下终止空字符初始化部分。 STRSAFE_IGNORE_NULLS 对待像(空字符串文字("")).空字符串指针 STRSAFE_FILL_ON_FAILURE 如果函数失败,在dwFlags(0)低字节是用来填充整个pszDest缓冲区,缓冲区空终止。在一个STRSAFE_E_INSUFFICIENT_BUFFER故障的情况下,任何截断的字符串返回的覆盖。 STRSAFE_NULL_ON_FAILURE 如果函数失败,pszDest设置为空字符串(文字("")).在一个STRSAFE_E_INSUFFICIENT_BUFFER故障的情况下,任何截断字符串覆盖。 STRSAFE_NO_TRUNCATION 正如STRSAFE_NULL_ON_FAILURE情况下,如果函数失败,pszDest设置为空字符串(文字("")).在一个STRSAFE_E_INSUFFICIENT_BUFFER故障的情况下,任何截断字符串覆盖。 pszFormat [in]指向缓冲区包含printf风格的格式字符串。此字符串必须是空终止。 ... [in]参数为可插入pszFormat。 返回值 请注意,此函数返回,而不是sprintf,它返回其目标缓冲区存储的字节数的hresult。我们强烈建议您使用的成功和失败宏来测试这个函数的返回值。 S_OKThere的结果是足够的空间被复制到pszDest没有截断和缓冲区空终止。 STRSAFE_E_INVALID_PARAMETERThe在cchDest值为0或比STRSAFE_MAX_CCH,或目标缓冲区大已经爆满。 STRSAFE_E_INSUFFICIENT_BUFFERThe复制操作失败,由于没有足够的缓冲空间。视乎dwFlags价值,目标缓冲区可能包含了预期的结果被截断,空终止的版本。截断的情况下是可以接受的,这未必是一个失败的情况出现。 备注 StringCchPrintfEx提供了代码中的适当缓冲处理额外的处理。可怜的缓冲处理是牵连,许多安全问题涉及缓冲区溢出。 StringCchPrintfEx总是空终止一个非零长度目标缓冲区。 StringCchPrintfEx可以用在它的通用形式,或作为StringCchPrintfExA特别(为ANSI字符串)或StringCchPrintfExW(为Unicode字符串)。该表格使用取决于您的数据。 字符串数据String类型LiteralFunction 字符“字符串”StringCchPrintfExA TCHARTEXT(“字符串”)StringCchPrintfEx WCHARL“字符串”StringCchPrintfExW StringCchPrintfEx及其ANSI和Unicode的变种替换这些功能: sprintf swprintf wsprintf wnsprintf _stprintf _snprintf _snwprintf _sntprintf 行为是未定义如果字符串指向pszDest,pszFormat,或任何参数字符串重叠。 无论pszFormat也不pszDest应该是NULL,除非STRSAFE_IGNORE_NULLS标志被指定,在这种情况下都可能为NULL。然而,由于一个错误没有足够的空间仍可能会返回空值,即使被忽略。 功能信息 Headerstrsafe.h import librarystrsafe.lib 参见 StringCbPrintfEx,StringCchPrintf,StringCchVPrintfEx ==英文原文==StringCchPrintfEx Function StringCchPrintfEx is a replacement for sprintf . It accepts a format string and a list of arguments and returns a formatted string. The size, in characters, of the destination buffer is provided to the function to ensure that StringCchPrintfEx does not write past the end of this buffer. StringCchPrintfEx adds to the functionality of StringCchPrintf by returning a pointer to the end of the destination string as well as the number of characters left unused in that string. Flags may also be passed to the function for additional control. Syntax HRESULT StringCchPrintfEx( LPTSTR pszDest, size_t cchDest, LPTSTR *ppszDestEnd, size_t *pcchRemaining, DWORD dwFlags, LPCTSTR pszFormat, ... ); Parameters pszDest [out] Pointer to a buffer which receives the formatted, null-terminated string created from pszFormat and its arguments. cchDest [in] Size of the destination buffer, in characters. This value must be sufficiently large to accommodate the final formatted string plus 1 to account for the terminating null character. The maximum number of characters allowed is STRSAFE_MAX_CCH. ppszDestEnd [out] Address of a pointer to the end of pszDest. If ppszDestEnd is non-NULL and any data is copied into the destination buffer, this points to the terminating null character at the end of the string. pcchRemaining [out] Pointer to a variable that indicates the number of unused characters in pszDest, including the terminating null character. If pcchRemaining is NULL, the count is not kept or returned. dwFlags [in] One or more of the following values. STRSAFE_FILL_BEHIND_NULL If the function succeeds, the low byte of dwFlags (0) is used to fill the uninitialized portion of pszDest following the terminating null character. STRSAFE_IGNORE_NULLS Treat null string pointers like empty strings (TEXT("")). STRSAFE_FILL_ON_FAILURE If the function fails, the low byte of dwFlags (0) is used to fill the entire pszDest buffer, and the buffer is null-terminated. In the case of a STRSAFE_E_INSUFFICIENT_BUFFER failure, any truncated string returned is overwritten. STRSAFE_NULL_ON_FAILURE If the function fails, pszDest is set to an empty string (TEXT("")). In the case of a STRSAFE_E_INSUFFICIENT_BUFFER failure, any truncated string is overwritten. STRSAFE_NO_TRUNCATION As in the case of STRSAFE_NULL_ON_FAILURE, if the function fails, pszDest is set to an empty string (TEXT("")). In the case of a STRSAFE_E_INSUFFICIENT_BUFFER failure, any truncated string is overwritten. pszFormat [in] Pointer to a buffer containing a printf -style format string. This string must be null-terminated. ... [in] Arguments to be inserted into pszFormat. Return Value Note that this function returns an HRESULT as opposed to sprintf, which returns the number of bytes stored in its destination buffer. It is strongly recommended that you use the SUCCEEDED and FAILED macros to test the return value of this function. S_OKThere was sufficient space for the result to be copied to pszDest without truncation and the buffer is null-terminated. STRSAFE_E_INVALID_PARAMETERThe value in cchDest is either 0 or larger than STRSAFE_MAX_CCH, or the destination buffer is already full. STRSAFE_E_INSUFFICIENT_BUFFERThe copy operation failed due to insufficient buffer space. Depending on the value of dwFlags, the destination buffer may contain 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 StringCchPrintfEx provides additional processing for proper buffer handling in your code. Poor buffer handling is implicated in many security issues that involve buffer overruns. StringCchPrintfEx always null-terminates a non-zero-length destination buffer. StringCchPrintfEx can be used in its generic form, or specifically as StringCchPrintfExA (for ANSI strings) or StringCchPrintfExW (for Unicode strings). The form to use is determined by your data. String Data TypeString LiteralFunction char"string"StringCchPrintfExA TCHARTEXT("string")StringCchPrintfEx WCHARL"string"StringCchPrintfExW StringCchPrintfEx and its ANSI and Unicode variants are replacements for these functions: sprintf swprintf wsprintf wnsprintf _stprintf _snprintf _snwprintf _sntprintf Behavior is undefined if the strings pointed to by pszDest, pszFormat, or any argument strings overlap. Neither pszFormat nor pszDest should be NULL unless the STRSAFE_IGNORE_NULLS flag is specified, in which case both may be NULL. However, an error due to insufficient space may still be returned even though null values are ignored. Function Information Headerstrsafe.h Import librarystrsafe.lib See Also StringCbPrintfEx , StringCchPrintf , StringCchVPrintfEx ==原始网址==http://msdn.microsoft.com/en-us/library/ms647543(VS.85).aspx\n |
随便看 |
|
windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。