Parameters
pszDest
[out] Pointer to a buffer that 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.
大出的那一位就是放结尾0的。字符串长度计算的时候不包括结尾0。事实上拷贝的时候不需要拷贝结尾0,但是缓冲区必须多设置一个字符,并且要置为0。
Examples
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."
深入理解StringCchPrintf函数使用及常见错误解决
本文详细介绍了StringCchPrintf函数的用法,包括参数解释、字符串长度计算规则以及如何避免常见错误。通过示例代码演示了函数的实际应用,并解决了在使用过程中遇到的兼容性问题。
766

被折叠的 条评论
为什么被折叠?



