GetBufferSetLength后需要ReleaseBuffer吗?比如CString test="China";
test.GetBufferSetLength(3); 返回应该是Chi,这样的话,是否需要ReleaseBuffer吗? 我知道GetBuffer后需要,

解决方案 »

  1.   

    If you use the pointer returned by GetBufferSetLength to change the string contents, you may need to call ReleaseBuffer before using any other CSimpleStringT member methods. The address returned by GetBufferSetLength may not be valid after the call to ReleaseBuffer because additional CSimpleStringT operations can cause the CSimpleStringT buffer to be reallocated. The buffer is not reassigned if you do not change the length of the CSimpleStringT. 
      

  2.   

    需要ReleaseBuffer
    GetBuffer不一定需要,只要你不修改缓冲区数据
      

  3.   

    The address returned by GetBufferSetLength may not be valid after the call to ReleaseBuffer since additional CString operations may cause the CString buffer to be reallocated. http://msdn.microsoft.com/en-us/library/aa300459(v=vs.60).aspx
      

  4.   

    CString有个成员专门保存了字符串的长度,所以一旦你直接操作并修改了字符串缓冲区,就必须调用ReleaseBuffer重新计算字符串长度更新这个成员
      

  5.   

    晕,楼上有分歧,算了,我还是用Mid吧,就我这个情况,接下来test的不会变,如果用GetBufferSetLength到底用不用release啊,直接说明白,我也会google,就求真相
      

  6.   

    不管是GetBufferSetLength还是GetBuffer,完了都必须要ReleaseBuffer。
      

  7.   

    GetBuffer修改了缓冲区的数据就要Realse下,要是没修改的话不需要Realse
      

  8.   

    调用了GetBuffer或者GetBufferSetLength方法并且修改了缓冲区里的内容之后,如果要调用其它的方法,就要先调用ReleaseBuffer或者ReleaseBufferSetLength方法