I've just had a similar problem right now. It has to do with the bool
type which was not supported on VC6.
I had this class:
class CTest
{
BOOL m_test ;
...
}
During deserialisation I did this at some point :
ar >> m_test ;
m_test = !m_test ;
And during serialisation I did this:
ar << !m_test ; // problem was here
Reminder: BOOL
is actually typedefd as int
on VC6 and on VC2010
As there is no true bool
type with VC6, the type of !m_test
is actually int and therefore ar << !m_test
calls CArchive::operator<<(int)
.
But on VC2010 the type of !m_test
is bool
and therefore CArchive::operator<<(BYTE)
gets called and you loose 3 bytes in your file. Then next time you deserialize the class, everything that comes after m_test
is shifted and we read garbage and the program could even crash.
The solution was simply to cast !m_test
to int
.
ar << (DWORD)!m_test ;