
David Klein wrote:
One of the data types though is MFC's CString - which is just like std:string, just a wrapper around a character array. The only way to get the contents of a CString as a char array is a function called GetBuffer() which returns a non-const char pointer to the internal array.
returns a non-const char pointer? so the mfc CString gives you a pointer to a buffer you might want to modify from outside the class? Looks like a bad idea to me. In any case I would use const_cast to cast the result to a "char const * const" to cast to a constant pointer to a const array of chars. This should do the trick. If you want to avoid sprinkling this syntactic vinegar through your code you mith make an non-intrusive serialization of mfc CString so you can just use: #include "...mfc/cstring.hpp" CString x; ... ar << x; ... ar >> x; Robert Ramey
My compiler does not seem to like this, as I guess the save() function is defined as const? Is this right, and if so, is there any way I can get around this one?
ar & m_3rdPartyClass.m_SomeCString.GetBuffer(); // returns non const char* !!
I don't know how serialization for std::string is done, but it's supported by the library. Maybe you could create a temporary std::string from your MFC string and serialize that one instead? Though there may be a decrease in performance if you have a lot of strings to deal with.