Please ignore this question. I scanned 176,000 threads in this group
to find all related to CMap. I finally discovered CMapWordToOb and
CMapStringToOb, which solved my problem. It's a shame that CMap
itself is not serializable... It looks like it should be and that
caused me to waste two days trying to go down the wrong road.
HI all. I have just started to try to use CMap, because it it seems
right for my application. After a lot of problems arose I found and
created a derived class from CMap, CMapEx. This seemed to resolve all
my issues with using CString with CMap, but the problem now is with
Serialization.
Serializaion almost works but there is a problem when reading in the
saved objects. when a CMap is read in, the values are read ok, but
then a call to AfxAssertValidObject is made. It makes several checks
and them does:
if (!AfxIsValidAddress(pOb, pOb->GetRuntimeClass()->m_nObjectSize, FALSE))
{
TRACE(traceAppMsg, 0, "ASSERT_VALID fails with illegal pointer.\n");
The program crashes when GetRuntimeClass is called. pObj itself
appears to be fine, points to my class object and contains all the
correct data, but CMap (and CMapEx) do not have DECLARE_SERIAL /
IMPLEMENT_SERIAL. I guess that is the problem, but I have been unable
to figure out a way to add that, and I am not even sure I need to.
In all the reading I have done about serializing CMap no one has said
or shown code indicating use of those macros. I can add
DECLARE_SERIAL ok, but IMPLEMENT_SERIAL can not be used with a
template - as far as I can tell - - all kinds of errors.
This is a MFC project, with static library linking using VC++ 2008.
Below is the implementation of my class that contains CMap objects:
enum ValueTypes { VTY_BOOL, VTY_RANGE, VTY_SYN, VTY_INT, VTY_DOUBLE };
class CValueData : public CObject {
public:
DECLARE_SERIAL (CValueData)
virtual const CValueData& operator= (const CValueData& in);
bool operator== (const CValueData& in) const;
bool operator!= (const CValueData& in) const { return ! (*this == in); }
void Serialize (CArchive &Ar);
CMapEx <CString, CString&, bool, bool> m_BoolVals;
CMapEx <UINT, UINT, UINT, UINT> m_RangeVals;
CMapEx <CString, CString&, int, int> m_IntVals;
CMapEx <CString, CString&, double, double&> m_DoubleVals;
CMapEx <CString, CString&, UINT, UINT> m_SynthVals;
CMapEx <CString, CString&, CString, CString&> m_Formats;
};
IMPLEMENT_SERIAL (CValueData, CObject, 1)
void CValueData::Serialize (CArchive &Ar)
{
m_BoolVals.Serialize (Ar);
m_RangeVals.Serialize (Ar);
m_SynthVals.Serialize (Ar);
m_IntVals.Serialize (Ar);
m_DoubleVals.Serialize (Ar);
m_Formats.Serialize (Ar);
}
const CValueData& CValueData::operator= (const CValueData& in)
{
m_BoolVals = in.m_BoolVals;
m_RangeVals = in.m_RangeVals;
...
return *this;
}
Finally all these objects are contained by another CMapEx that looks
like:
CMapEx <ValueTypes, ValueTypes, CValueData, CValueData&> m_ValDataList;
and is serialized by another class serialization:
void CDataTableList::Serialize (CArchive &Ar)
{
ValueTypes type;
CValueData Vd;
m_Hdr.Serialize (Ar);
m_ValDataList.Serialize (Ar);
CObList::Serialize (Ar);
}
Can anyone tell me hos to fix this?
Thanks, Russ