[Debugging] How to find length of a CString string in application memory or in a dump

Recently a colleague of mine asked where’s the length of CString string stored in memory. Hmm so lets dig around. Please note I’ve declared the following CString object in my code… CString TestCString = _T(“Nibu is testing CString”); If you dump CString type in the debugger we see following… 0:000> dt TestCStringLocal var @ 0xb4fcd4 […]
Continue reading…

 

Converting CString to LPCTSTR or LPTSTR

Converting from CString to char* is conditional, becuase CString is a TCHAR based implementation. TCHAR is defined as a char if _UNICODE is not defined, so if this is the case we can convert to char*, since TCHAR* and char*  are equal, else we’ve got to use function like MultiByteToWideChar/W2A/W2AEX etc. So from now on […]
Continue reading…

 

How to trim white space before and after a string?

I will describe in this post three ways to trim a string of given characters… Using custom function for std::string Using CString Using StrTrim shell API function. Using custom function for std::string Its bit strange that std::string doesn’t provide a Trim function 😕 , but hey since we’ve got head upon our shoulders we’re gonna […]
Continue reading…

 

Replacement for CString::Format in standard C++

std::stringstream can be used as a replacement for CString::Format, if you are using CString just for the sake of Format, caveat being that it could be slow, I’ve heard a user mentioning this but not sure, I haven’t tested it out, but should be definitely better that using CString::Format and then assigning to std::string. [sourcecode […]
Continue reading…

 

A TCHAR version of std stream and string classes

Quite simple… [sourcecode language=’cpp’]// A TCHAR based std::string typedef std::basic_string tstring; // A TCHAR based std::ifstream; typedef std::basic_ifstream tstream; // A TCHAR based std::stringstream typedef std::basic_stringstream tstringstream;[/sourcecode] So now no need to worry about UNICODE and ANSI, should work as CString, since TCHAR becomes char/wchar_t based on _UNICODE macro definition. Also note that stl has […]
Continue reading…