当前位置: 代码迷 >> 汇编语言 >> GetDlgItemText API函数取得的字符最后一位是空字节?该如何处理
  详细解决方案

GetDlgItemText API函数取得的字符最后一位是空字节?该如何处理

热度:5063   发布时间:2013-02-26 00:00:00.0
GetDlgItemText API函数取得的字符最后一位是空字节?
为什么GetDlgItemText API函数取得的字符最后一位是空字节,这样定义定义变量长度的时候就必须比实际输入的字符长度要多一位是不是。

------解决方案--------------------------------------------------------
lpString
[out] Pointer to the buffer to receive the title or text. 
nMaxCount
[in] Specifies the maximum length, in TCHARs, of the string to be copied to the buffer pointed to by lpString. If the length of the string, including the NULL character, exceeds the limit, the string is truncated. 



If the string is as long or longer than the buffer, the buffer will contain the truncated string with a terminating NULL character.


c风格的字符串是以'\0'结尾的,所以假如字符串长度是10字节,实际上是11字节,最后有个'\0'