serializationmfc32bit-64bitporting

CStringArray MFC serialization on 32bit and deserialization on 64 bit


I'm struggling a lot porting an MFC application from 32bit to 64bit. I have same classes with CStringArray members and they use the CArchive serialization and all works fine in 32 bit app.

Now I split the same application into two parts, one in 32bit and the other in 64 bit and they need to share some serialized data; when I serialize a CStringArray member and try to deserialize it in the 64 bit app I get an CArchiveException, with cause=3 that should be "endOfFile".

It's not clear what's going on, I suspect that I can't serialize it a data in 32 bit and read it on 64 bit app due to the size. If I follow the GetSize() function of CStringArray, I see that the return is INT_PTR that is defined as follows:

Defined of INT_PTR

This means there is no way to make a CStringArray serialization on 32bit and deserialization on 64 bit? Exist an workaround or something similar? There are other MFC data that I should check between 32 and 64 app?

EDIT: The problem is not related strictly on the CStringArray that (see the comments) is fine between 32/64.


Solution

  • I answer to my question for future readers. The problem was not related to the CStringArray but to other parts of code near it. The problem was that before CStringArray obj there is another member that was an CArray of a custom struct. This struct have a couple of members that use an override of the CArchive SerializeElements function to made a correct data serialization in 32 bit.

    This serialize element was written in this way:

    template<class TYPE> void AFXAPI SerializeElements (CArchive& ar, CRect* pElements, int nCount);
    

    but the 64bit version does not use this override because the last parameter was int instead of INT_PTR and without using SerializeElements, I made a wrong serialization (less byte that needed, this is why I reach the endOfFile to soon while reading).

    To fix it, just use the right declaration for the SerializeElements that is:

    template<class TYPE> void AFXAPI SerializeElements (CArchive& ar, CRect* pElements, **INT_PTR** nCount);
    

    Notice int => INT_PTR.

    I hope it can help.