INSUFFICIENT_BUFFER when use CString::GetBuffer(dwSize) & CString::ReleaseBuffer()

When I use CString::GetBuffer(dwSize) & CString::ReleaseBuffer(), I often encount such problem of INSUFFICIENT BUFFER. May you help me and tell me why?
Thank you very much!
happy050597Asked:
Who is Participating?
 
subbaiahConnect With a Mentor Commented:
If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions.

The address returned by GetBuffer may not be valid after the call to ReleaseBuffer since additional CString operations may cause the CString buffer to be reallocated. The buffer will not be reallocated if you do not change the length of the CString.

The buffer memory will be freed automatically when the CString object is destroyed.


0
 
chensuCommented:
Where did you get this error? Did it throw a CMemoryException? What's the value of dwSize?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.