wxSerialize

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
NinjaNL
Moderator
Moderator
Posts: 899
Joined: Sun Oct 03, 2004 10:33 am
Location: Oosterwolde, Netherlands

wxSerialize

Post by NinjaNL »

Hello All,

I was wondering what had happened to Jorg's wxSerialize classes.

I am investigating porting a MFC project to wxWidgets and I understood that wxSerialize classes could replace the MFC CArchive ones.

Any help?

TIA
Follow the development of my screenplay authoring program at http://wxscreenplaywriter.blogspot.com/
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: wxSerialize

Post by catalin »

robbie
In need of some credit
In need of some credit
Posts: 4
Joined: Mon Mar 04, 2013 7:19 pm

Re: wxSerialize

Post by robbie »

I´d like to convert my MFC project to wxWidgets, but can anyone confirm if I will be able to load my Windows MFC app produced files, which use CObjects, CStrings, etc., directly via wxSerialize?
GlenWalker
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Jan 07, 2014 8:08 am

Re: wxSerialize

Post by GlenWalker »

I am in the process of trying to do exactly that. We have a program that has previously been written using MFC and stores its save files as an MFC CArchive.

I am attempting to use Jorg's wxSerialize to read the files but have not met with any success so far (wxSerialize is working nicely and I can create new archives and read from them no problem, but I cannot read the archives created by CArchive).
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxSerialize

Post by iwbnwif »

For reference there is an XML serializer here http://sourceforge.net/projects/wxxs/.

Of course it won't read MFC serializations but you will end up with XML files which might be easier to parse if you implement a format change in future. Just a thought :) .
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
robbie
In need of some credit
In need of some credit
Posts: 4
Joined: Mon Mar 04, 2013 7:19 pm

Re: wxSerialize

Post by robbie »

How difficult could it be to take the MFC c++ files and use them in wxwidgets?

We just need to add CObjects, CString, CObjectArray, all fairly standard C++ classes, and CArchive...

I´d be surprised that no one has done that yet.
GlenWalker
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Jan 07, 2014 8:08 am

Re: wxSerialize

Post by GlenWalker »

Thanks iwbnwif, I doubt that a format change is something we can do but I will consider it...

I'm not sure that XML would be suitable since our save files generally get very large (possibly the original reason they were stored as binary archives, although its more likely that MFC was used because of the Windows-centric development path that the software has taken).

robbie: I would definatley be interested if we could create a library that could handle MFC stored binaries in wxWidgets, it would overcome the barrier that I'm currently facing! I'm not sure how easy it would be to do though...?
robbie
In need of some credit
In need of some credit
Posts: 4
Joined: Mon Mar 04, 2013 7:19 pm

Re: wxSerialize

Post by robbie »

At least all the MFC sources are available. CObject is the base class, so adding that plus CArchive would get basic serialisation working. Then we could partially add the remaining key classes, such as CString - perhaps converting to wx String rather than implementing all of CString.
GlenWalker
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Jan 07, 2014 8:08 am

Re: wxSerialize

Post by GlenWalker »

I'm not sure if its true of all the versions of wxSerialize, but the one that I have (1.16) puts a version and header entry to the start of the file which the CArchive files do not have - I think this is one of the causes for wxSerialise failing to open the CArchive files, wxSerialise looks for the version and header, then when it can't find them it seems to keep scanning the file until it reaches the end and then fails with an error saying "end of file reached".

The CArchive files I have do contain some unsigned shorts at the start though so I could try to make wxSerialise think that one of these is the version number...I might have a go at that some time later...

Also, there appears to be a memory leak in wxSerialize (or in the way I'm using it) that makes the memory use jump alarmingly so that would have to be nailed before I propose a full conversion to wxWidgets.

I have the CArchive doing what it should for now so will stick to that (using a mixture of wxWidgets and MFC) and come back to this issue later...I'm quite suprised that there is so little information regarding wxSerialize available on the net but then I guess that since it was created in 2007 and has not made it into the main part of wxWidgets that not many people use it?
GlenWalker
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Jan 07, 2014 8:08 am

Re: wxSerialize

Post by GlenWalker »

I know it has been a while but just thought I'd post an update!

I successfully managed to get the data out that I needed using wxDataInputStream as follows:

Code: Select all

wxFileInputStream inputFile(openDialog->GetPath());
wxDataInputStream inputData(inputFile);
inputData.UseBasicPrecisions();

wxUint16 versionByte, versionByte2, unicodePrefix, fileType, fileVersion;
wxUint8 lengthPrefix, messageLength;

inputData >> versionByte >> versionByte2;
inputData >> unicodePrefix;
inputData >> lengthPrefix;
inputData >> messageLength;

wxUint16 *message = new wxUint16[messageLength];
for (wxUint8 i = 0 ; i < messageLength ; i++)
{
    inputData >> message[i];
}

inputData >> fileType >> fileVersion;

The above code may be specific to the application I was using but hopefully it will be of use or inspiration to someone. Basically I jumped through a few hoops in order to correctly extract a CString as bytes (from the Microsoft website the CString uses a unicode prefix and a length prefix before the actual data/content of the string).

Also extracted in the example above were a couple of bytes that held the file type and file version. The real method I had then extracted all the bytes from the archive sequentially (its fairly tedious so not shown here).

Essentially you have to know the type of data, and the order of the data, that has been serialized into the CArchive and then extract it manually - I never managed to get wxSerialize to do very much...
robbie
In need of some credit
In need of some credit
Posts: 4
Joined: Mon Mar 04, 2013 7:19 pm

Re: wxSerialize

Post by robbie »

It´s good to know that works and I am sure many people converting from MFC will find it useful. I guess adding support for cstrings and cstringarrays etc., shouldn´t be too difficult.
Post Reply