网站首页  词典首页

请输入您要查询的函数:

 

术语 stringcchprintf
释义 StringCchPrintf
语法:
HRESULT StringCchPrintf( LPTSTR pszDest,
size_t cchDest,
LPCTSTR pszFormat,
...
);
StringCchPrintf功能
StringCchPrintf是一个sprintf更换。它接受一个格式字符串和参数,并返回一个格式化字符串列表。大小,以字符缓冲区的目标是提供的功能,以确保不会写入StringCchPrintf过去这个缓冲区的末尾。
参数
pszDest
[out]指向一个缓冲区的接收格式,NULL结尾的字符串从pszFormat和它的参数创建。
cchDest
[in]的目标缓冲区的大小,以字符。此值必须足够大,以满足最终格式化字符串加1占终止空字符。所允许的最大字符数为STRSAFE_MAX_CCH。
pszFormat
[in]指向缓冲区包含printf风格的格式字符串。此字符串必须是空终止。
...
[in]参数为可插入pszFormat。
返回值
请注意,此函数返回,而不是sprintf,它返回其目标缓冲区存储的字节数的hresult。我们强烈建议您使用的成功和失败宏来测试这个函数的返回值。
S_OKThere的结果是足够的空间被复制到pszDest没有截断,并缓冲区空终止。
STRSAFE_E_INVALID_PARAMETERThe在cchDest值为0或比STRSAFE_MAX_CCH更大。
STRSAFE_E_INSUFFICIENT_BUFFERThe复制操作失败,由于没有足够的缓冲空间。目标缓冲区包含了预期的结果被截断,空终止的版本。截断的情况下是可以接受的,这未必是一个失败的情况出现。
备注
StringCchPrintf提供了代码中的适当缓冲处理额外的处理。可怜的缓冲处理是牵连,许多安全问题涉及缓冲区溢出。 StringCchPrintf总是空终止一个非零长度目标缓冲区。
StringCchPrintf可以用在它的通用形式,或作为StringCchPrintfA特别(为ANSI字符串)或StringCchPrintfW(为Unicode字符串)。该表格使用取决于您的数据。
字符串数据String类型LiteralFunction
字符“字符串”StringCchPrintfA
TCHARTEXT(“字符串”)StringCchPrintf
WCHARL“字符串”StringCchPrintfW
StringCchPrintf及其ANSI和Unicode的变种替换这些功能:
sprintf
swprintf
wsprintf
wnsprintf
_stprintf
_snprintf
_snwprintf
_sntprintf
行为是未定义如果字符串指向pszDest,pszFormat,或任何参数字符串重叠。
无论pszFormat也不pszDest应为NULL。见StringCchPrintfEx如果您需要的空字符串指针值的处理。
例如
下面的例子显示了StringCchPrintf使用简单,使用四个参数。
TCHAR pszDest [30];
size_t cchDest = 30;
LPCTSTR pszFormat =文字(“%d个%? +%d个=%d的”);
TCHAR * pszTxt =文字(“答案是”);
的hresult小时= StringCchPrintf(pszDest,cchDest,pszFormat,pszTxt,1,2,3);
/ /位于pszDest结果字符串是“答案是1 +2 = 3。”
功能信息
Headerstrsafe.h
import librarystrsafe.lib
参见
StringCbPrintf,StringCchPrintfEx,StringCchVPrintf
==英文原文==StringCchPrintf Function
StringCchPrintf 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 StringCchPrintf does not write past the end of this buffer.
Syntax
HRESULT StringCchPrintf( LPTSTR pszDest,
size_t cchDest,
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.
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.
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
StringCchPrintf provides additional processing for proper buffer handling in your code. Poor buffer handling is implicated in many security issues that involve buffer overruns. StringCchPrintf always null-terminates a non-zero-length destination buffer.
StringCchPrintf can be used in its generic form, or specifically as StringCchPrintfA (for ANSI strings) or StringCchPrintfW (for Unicode strings). The form to use is determined by your data.
String Data TypeString LiteralFunction
char"string"StringCchPrintfA
TCHARTEXT("string")StringCchPrintf
WCHARL"string"StringCchPrintfW
StringCchPrintf 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. See StringCchPrintfEx if you require the handling of null string pointer values.
Example
The following example shows a simple use of StringCchPrintf, using four arguments.
TCHAR pszDest[30];
size_t cchDest = 30;
LPCTSTR pszFormat = TEXT("%s %d + %d = %d.");
TCHAR* pszTxt = TEXT("The answer is");
HRESULT hr = StringCchPrintf(pszDest, cchDest, pszFormat, pszTxt, 1, 2, 3);
// The resultant string at pszDest is "The answer is 1 + 2 = 3."
Function Information
Headerstrsafe.h
Import librarystrsafe.lib
See Also
StringCbPrintf , StringCchPrintfEx , StringCchVPrintf
==原始网址==http://msdn.microsoft.com/en-us/library/ms647541(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:20:31