Re: How to modify CString in the debugger for VC6.0? by Alex
Alex
Wed Jun 01 10:47:08 CDT 2005
malhenry wrote:
> I could not find any reference to CStringData.nDataLength
> member in the watch window.
It won't appear in watch window, since there is no such
member in CString. CStringData is a class that maintains
string length, buffer length and reference counting. Several
CString instances can share single CStringData instance.
CStringData is allocated before actual string buffer, so
memory layout is like that:
0x00200000 +------------------+ <-- CStringData
| long nRefs |
0x00200004 +------------------+
| int nDataLength |
0x00200008 +------------------+
| int nAllocLength |
0x0020000C +------------------+ <-- CString.m_pchData
| LPTSTR m_pchData |
| ... |
| ... |
+------------------+
So, to get correct CStringData instance you need to subtract
12 from CString.m_pchData address (write it in watch
window):
(CStringData*)(strHello.m_pchData - 12)
Warning: If you see that CStringData.nRefs is more than 1,
then you cannot change string buffer pointed by
CString.m_pchData because some other CString instance(s)
share(s) string buffer with current instance. By changing it
you will change string for them all.