|
Boost Users : |
From: Jeffrey McBeth (mcbeth_at_[hidden])
Date: 2007-02-09 12:29:56
Quoting David Klein <dave_chp_at_[hidden]>:
> Mark Wyszomierski 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. 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.
Try casting it to an LPCTSTR. That should actually be far enough for
the Serializer to work, as that is const pointer to a TChar array, and
TChar is simply a wchar_t or char depending on if you have Unicode
turned on. I wouldn't put any bets on the serialized data loading
into another app that was compiled with the opposite Unicode setting.
ar & (LPCTSTR)(m_3rdPartyClass.m_SomeCString);
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net